Skip to content

Commit fe9feb3

Browse files
authored
Rollup merge of rust-lang#137741 - cuviper:const_str-raw_entry, r=Mark-Simulacrum
Stop using `hash_raw_entry` in `CodegenCx::const_str` That unstable feature (rust-lang#56167) completed fcp-close, so the compiler needs to be migrated away to allow its removal. In this case, `cg_llvm` and `cg_gcc` were using raw entries to optimize their `const_str_cache` lookup and insertion. We can change that to separate `get` and (on miss) `insert` calls, so we still have the fast path avoiding string allocation when the cache hits.
2 parents d344960 + 7721431 commit fe9feb3

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/common.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@ impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
146146
}
147147

148148
fn const_str(&self, s: &str) -> (RValue<'gcc>, RValue<'gcc>) {
149-
let str_global = *self
150-
.const_str_cache
151-
.borrow_mut()
152-
.raw_entry_mut()
153-
.from_key(s)
154-
.or_insert_with(|| (s.to_owned(), self.global_string(s)))
155-
.1;
149+
let mut const_str_cache = self.const_str_cache.borrow_mut();
150+
let str_global = const_str_cache.get(s).copied().unwrap_or_else(|| {
151+
let g = self.global_string(s);
152+
const_str_cache.insert(s.to_owned(), g);
153+
g
154+
});
156155
let len = s.len();
157156
let cs = self.const_ptrcast(
158157
str_global.get_address(None),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#![allow(internal_features)]
1717
#![doc(rust_logo)]
1818
#![feature(rustdoc_internals)]
19-
#![feature(rustc_private, decl_macro, never_type, trusted_len, hash_raw_entry, let_chains)]
19+
#![feature(rustc_private, decl_macro, never_type, trusted_len, let_chains)]
2020
#![allow(broken_intra_doc_links)]
2121
#![recursion_limit = "256"]
2222
#![warn(rust_2018_idioms)]

0 commit comments

Comments
 (0)