diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2022-06-28 17:34:24 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2022-06-28 18:38:36 +0000 |
| commit | f6484fa9b59585cf0609aa6f047015270f6e1d19 (patch) | |
| tree | 80aa1a90f9ab2ca00f528ba58b400d9daa416663 /compiler/rustc_codegen_gcc/src/common.rs | |
| parent | 94e93749ab00539a11e90426ea87382c433530a8 (diff) | |
| download | rust-f6484fa9b59585cf0609aa6f047015270f6e1d19.tar.gz rust-f6484fa9b59585cf0609aa6f047015270f6e1d19.zip | |
Avoid unnecessary string interning for const_str
Diffstat (limited to 'compiler/rustc_codegen_gcc/src/common.rs')
| -rw-r--r-- | compiler/rustc_codegen_gcc/src/common.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/compiler/rustc_codegen_gcc/src/common.rs b/compiler/rustc_codegen_gcc/src/common.rs index ce341406eaf..d156f874434 100644 --- a/compiler/rustc_codegen_gcc/src/common.rs +++ b/compiler/rustc_codegen_gcc/src/common.rs @@ -12,7 +12,6 @@ use rustc_middle::mir::Mutability; use rustc_middle::ty::ScalarInt; use rustc_middle::ty::layout::{TyAndLayout, LayoutOf}; use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar}; -use rustc_span::Symbol; use rustc_target::abi::{self, HasDataLayout, Pointer, Size}; use crate::consts::const_alloc_to_gcc; @@ -125,12 +124,15 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { self.context.new_rvalue_from_double(typ, val) } - fn const_str(&self, s: Symbol) -> (RValue<'gcc>, RValue<'gcc>) { - let s_str = s.as_str(); - let str_global = *self.const_str_cache.borrow_mut().entry(s).or_insert_with(|| { - self.global_string(s_str) - }); - let len = s_str.len(); + fn const_str(&self, s: &str) -> (RValue<'gcc>, RValue<'gcc>) { + let str_global = *self + .const_str_cache + .borrow_mut() + .raw_entry_mut() + .from_key(s) + .or_insert_with(|| (s.to_owned(), self.global_string(s))) + .1; + let len = s.len(); let cs = self.const_ptrcast(str_global.get_address(None), self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self, true)), ); |
