diff options
| author | Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com> | 2020-09-17 10:56:08 +0800 |
|---|---|---|
| committer | Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com> | 2020-09-17 11:03:08 +0800 |
| commit | f4a7149f499a4b91d296678002f0bce4ded85038 (patch) | |
| tree | c852698c0cfae5399c25135f1fc58990f8a3fa0f | |
| parent | 285fc7d704fcdd7b2a37d475d04d5d955490e000 (diff) | |
| download | rust-f4a7149f499a4b91d296678002f0bce4ded85038.tar.gz rust-f4a7149f499a4b91d296678002f0bce4ded85038.zip | |
Don't compile regex at every function call.
Use `SyncOnceCell` to only compile it once. I believe this still adds some kind of locking mechanism?
| -rw-r--r-- | compiler/rustc_mir/src/dataflow/framework/graphviz.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/lib.rs | 1 |
2 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_mir/src/dataflow/framework/graphviz.rs b/compiler/rustc_mir/src/dataflow/framework/graphviz.rs index 94151fbd090..5d4c4251961 100644 --- a/compiler/rustc_mir/src/dataflow/framework/graphviz.rs +++ b/compiler/rustc_mir/src/dataflow/framework/graphviz.rs @@ -1,6 +1,7 @@ //! A helpful diagram for debugging dataflow problems. use std::borrow::Cow; +use std::lazy::SyncOnceCell; use std::{io, ops, str}; use regex::Regex; @@ -570,6 +571,13 @@ where } } +macro_rules! regex { + ($re:literal $(,)?) => {{ + static RE: SyncOnceCell<regex::Regex> = SyncOnceCell::new(); + RE.get_or_init(|| Regex::new($re).unwrap()) + }}; +} + fn diff_pretty<T, C>(new: T, old: T, ctxt: &C) -> String where T: DebugWithContext<C>, @@ -578,7 +586,7 @@ where return String::new(); } - let re = Regex::new("\t?\u{001f}([+-])").unwrap(); + let re = regex!("\t?\u{001f}([+-])"); let raw_diff = format!("{:#?}", DebugDiffWithAdapter { new, old, ctxt }); diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index 42717f27384..8d2253b4d82 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -27,6 +27,7 @@ Rust MIR: a lowered representation of Rust. #![feature(trait_alias)] #![feature(option_expect_none)] #![feature(or_patterns)] +#![feature(once_cell)] #![recursion_limit = "256"] #[macro_use] |
