We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e3b3ed8 commit 0ca2245Copy full SHA for 0ca2245
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)]
@@ -64,11 +60,11 @@ impl Eq for InternedString {}
64
60
impl InternedString {
65
61
pub fn new(str: &str) -> InternedString {
66
62
let mut cache = STRING_CACHE
67
- .get_or_init(|| Default::default())
63
+ .get_or_init(Default::default)
68
.lock()
69
.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