diff --git a/src/common.rs b/src/common.rs index ce341406eaf..d156f874434 100644 --- a/src/common.rs +++ b/src/common.rs @@ -12,7 +12,6 @@ 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 @@ fn const_real(&self, typ: Type<'gcc>, val: f64) -> RValue<'gcc> { 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)), ); diff --git a/src/context.rs b/src/context.rs index 44f36cfa4ca..478f6d893dd 100644 --- a/src/context.rs +++ b/src/context.rs @@ -13,7 +13,7 @@ use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout, LayoutOfHelpers}; use rustc_session::Session; -use rustc_span::{Span, Symbol}; +use rustc_span::Span; use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx}; use rustc_target::spec::{HasTargetSpec, Target, TlsModel}; @@ -101,7 +101,7 @@ pub struct CodegenCx<'gcc, 'tcx> { pub global_lvalues: RefCell, LValue<'gcc>>>, /// Cache of constant strings, - pub const_str_cache: RefCell>>, + pub const_str_cache: RefCell>>, /// Cache of globals. pub globals: RefCell>>, diff --git a/src/lib.rs b/src/lib.rs index 5bfdeb8b93a..399830de84c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,14 @@ * TODO(antoyo): remove the patches. */ -#![feature(rustc_private, decl_macro, associated_type_bounds, never_type, trusted_len)] +#![feature( + rustc_private, + decl_macro, + associated_type_bounds, + never_type, + trusted_len, + hash_raw_entry +)] #![allow(broken_intra_doc_links)] #![recursion_limit="256"] #![warn(rust_2018_idioms)]