Skip to content

Commit 02ba57d

Browse files
authored
Merge pull request #287 from DaniPopes/cache-regex
Cache an error parser regex
2 parents a0ddf64 + 9d379fb commit 02ba57d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/rustc_stderr.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use crate::diagnostics::{Diagnostics, Message};
22
use bstr::ByteSlice;
33
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticSpan};
44
use regex::Regex;
5-
use std::path::{Path, PathBuf};
5+
use std::{
6+
path::{Path, PathBuf},
7+
sync::OnceLock,
8+
};
69

710
fn diag_line(diag: &Diagnostic, file: &Path) -> Option<(spanned::Span, usize)> {
811
let span = |primary| {
@@ -83,8 +86,10 @@ fn span_line(span: &DiagnosticSpan, file: &Path, primary: bool) -> Option<(spann
8386
}
8487

8588
fn filter_annotations_from_rendered(rendered: &str) -> std::borrow::Cow<'_, str> {
86-
let annotations = Regex::new(r" *//(\[[a-z,]+\])?~.*").unwrap();
87-
annotations.replace_all(rendered, "")
89+
static ANNOTATIONS_RE: OnceLock<Regex> = OnceLock::new();
90+
ANNOTATIONS_RE
91+
.get_or_init(|| Regex::new(r" *//(\[[a-z,]+\])?~.*").unwrap())
92+
.replace_all(rendered, "")
8893
}
8994

9095
pub(crate) fn process(file: &Path, stderr: &[u8]) -> Diagnostics {

0 commit comments

Comments
 (0)