We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e3b3ed8 commit 329af64Copy full SHA for 329af64
src/cargo/util/interning.rs
@@ -12,10 +12,6 @@ use std::str;
12
use std::sync::Mutex;
13
use std::sync::OnceLock;
14
15
-fn leak(s: String) -> &'static str {
16
- Box::leak(s.into_boxed_str())
17
-}
18
-
19
static STRING_CACHE: OnceLock<Mutex<HashSet<&'static str>>> = OnceLock::new();
20
21
#[derive(Clone, Copy)]
@@ -63,12 +59,9 @@ impl Eq for InternedString {}
63
59
64
60
impl InternedString {
65
61
pub fn new(str: &str) -> InternedString {
66
- let mut cache = STRING_CACHE
67
- .get_or_init(|| Default::default())
68
- .lock()
69
- .unwrap();
62
+ let mut cache = STRING_CACHE.get_or_init(Default::default).lock().unwrap();
70
let s = cache.get(str).cloned().unwrap_or_else(|| {
71
- let s = leak(str.to_string());
+ let s = str.to_string().leak();
72
cache.insert(s);
73
s
74
});
0 commit comments