Skip to content

Commit 7c1340d

Browse files
committed
perf(diagnostics): Info::new trim string in place
1 parent bc9ddcc commit 7c1340d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/oxc_diagnostics/src/reporter.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,17 @@ impl Info {
138138
if matches!(diagnostic.severity(), Some(Severity::Error)) {
139139
severity = Severity::Error;
140140
}
141-
let msg = diagnostic.to_string();
142141

143-
// Our messages usually comes with `eslint(rule): message`
144-
message = msg
145-
.split_once(':')
146-
.map_or_else(|| msg.to_string(), |(_, msg)| msg.trim().to_string());
142+
message = diagnostic.to_string();
143+
// Our messages usually are in format `eslint(rule): message`.
144+
// Trim off before the colon.
145+
if let Some((_, msg)) = message.split_once(':') {
146+
// Equivalent to `message = msg.trim().to_string()`, but operates in place
147+
let msg = msg.trim();
148+
let start = msg.as_ptr() as usize - message.as_str().as_ptr() as usize;
149+
message.truncate(start + msg.len());
150+
message.replace_range(..start, "");
151+
}
147152
}
148153
}
149154
}

0 commit comments

Comments
 (0)