Skip to content

Commit 329af64

Browse files
committed
string leek is stable
1 parent e3b3ed8 commit 329af64

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/cargo/util/interning.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ use std::str;
1212
use std::sync::Mutex;
1313
use std::sync::OnceLock;
1414

15-
fn leak(s: String) -> &'static str {
16-
Box::leak(s.into_boxed_str())
17-
}
18-
1915
static STRING_CACHE: OnceLock<Mutex<HashSet<&'static str>>> = OnceLock::new();
2016

2117
#[derive(Clone, Copy)]
@@ -63,12 +59,9 @@ impl Eq for InternedString {}
6359

6460
impl InternedString {
6561
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();
7063
let s = cache.get(str).cloned().unwrap_or_else(|| {
71-
let s = leak(str.to_string());
64+
let s = str.to_string().leak();
7265
cache.insert(s);
7366
s
7467
});

0 commit comments

Comments
 (0)