Skip to content

Commit

Permalink
Auto merge of rust-lang#12559 - Eh2406:new_rustc, r=weihanglo
Browse files Browse the repository at this point in the history
string leek is stable

### What does this PR try to resolve?

String leek is now stable so lets use it.

### How should we test and review this PR?

Code compiles and test run.
  • Loading branch information
bors committed Aug 25, 2023
2 parents f797978 + 329af64 commit 925280f
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 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 @@ -63,12 +59,9 @@ impl Eq for InternedString {}

impl InternedString {
pub fn new(str: &str) -> InternedString {
let mut cache = STRING_CACHE
.get_or_init(|| Default::default())
.lock()
.unwrap();
let mut cache = STRING_CACHE.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 925280f

Please sign in to comment.