Skip to content

Commit

Permalink
string leek is stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Aug 25, 2023
1 parent e3b3ed8 commit 0ca2245
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/cargo/util/interning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ use std::str;
use std::sync::Mutex;
use std::sync::OnceLock;

fn leak(s: String) -> &'static str {
Box::leak(s.into_boxed_str())
}

static STRING_CACHE: OnceLock<Mutex<HashSet<&'static str>>> = OnceLock::new();

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -64,11 +60,11 @@ impl Eq for InternedString {}
impl InternedString {
pub fn new(str: &str) -> InternedString {
let mut cache = STRING_CACHE
.get_or_init(|| Default::default())
.get_or_init(Default::default)
.lock()
.unwrap();
let s = cache.get(str).cloned().unwrap_or_else(|| {
let s = leak(str.to_string());
let s = str.to_string().leak();
cache.insert(s);
s
});
Expand Down

0 comments on commit 0ca2245

Please sign in to comment.