Skip to content

Commit

Permalink
Merge pull request #287 from DaniPopes/cache-regex
Browse files Browse the repository at this point in the history
Cache an error parser regex
  • Loading branch information
oli-obk authored Oct 13, 2024
2 parents a0ddf64 + 9d379fb commit 02ba57d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/rustc_stderr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::diagnostics::{Diagnostics, Message};
use bstr::ByteSlice;
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticSpan};
use regex::Regex;
use std::path::{Path, PathBuf};
use std::{
path::{Path, PathBuf},
sync::OnceLock,
};

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

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

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

0 comments on commit 02ba57d

Please sign in to comment.