Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(diagnostic): use Cow<'static, str> over String #4175

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod reporter;
mod service;

use std::{
borrow::Cow,
fmt::{self, Display},
ops::Deref,
};
Expand Down Expand Up @@ -42,9 +43,9 @@ impl Deref for OxcDiagnostic {

#[derive(Debug, Clone)]
pub struct OxcDiagnosticInner {
pub message: String,
pub message: Cow<'static, str>,
pub labels: Option<Vec<LabeledSpan>>,
pub help: Option<String>,
pub help: Option<Cow<'static, str>>,
pub severity: Severity,
}

Expand Down Expand Up @@ -76,7 +77,7 @@ impl Diagnostic for OxcDiagnostic {

impl OxcDiagnostic {
#[must_use]
pub fn error<T: Into<String>>(message: T) -> Self {
pub fn error<T: Into<Cow<'static, str>>>(message: T) -> Self {
Self {
inner: Box::new(OxcDiagnosticInner {
message: message.into(),
Expand All @@ -88,7 +89,7 @@ impl OxcDiagnostic {
}

#[must_use]
pub fn warn<T: Into<String>>(message: T) -> Self {
pub fn warn<T: Into<Cow<'static, str>>>(message: T) -> Self {
Self {
inner: Box::new(OxcDiagnosticInner {
message: message.into(),
Expand All @@ -106,7 +107,7 @@ impl OxcDiagnostic {
}

#[must_use]
pub fn with_help<T: Into<String>>(mut self, help: T) -> Self {
pub fn with_help<T: Into<Cow<'static, str>>>(mut self, help: T) -> Self {
self.inner.help = Some(help.into());
self
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/oxc/no_optional_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn no_optional_chaining_diagnostic(span0: Span, x1: &str) -> OxcDiagnostic {
.with_label(span0)
} else {
OxcDiagnostic::warn("oxc(no-optional-chaining): Optional chaining is not allowed.")
.with_help(x1)
.with_help(x1.to_owned())
.with_label(span0)
}
}
Expand Down
Loading