Skip to content

Commit 4587677

Browse files
committed
Auto merge of #98638 - bjorn3:less_string_interning, r=tmiasko
Use less string interning This removes string interning in a couple of places where doing so won't result in perf improvements. I also switched one place to use pre-interned symbols.
2 parents 97b7dc2 + c0ec18b commit 4587677

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/common.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_middle::mir::Mutability;
1212
use rustc_middle::ty::ScalarInt;
1313
use rustc_middle::ty::layout::{TyAndLayout, LayoutOf};
1414
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
15-
use rustc_span::Symbol;
1615
use rustc_target::abi::{self, HasDataLayout, Pointer, Size};
1716

1817
use crate::consts::const_alloc_to_gcc;
@@ -125,12 +124,15 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
125124
self.context.new_rvalue_from_double(typ, val)
126125
}
127126

128-
fn const_str(&self, s: Symbol) -> (RValue<'gcc>, RValue<'gcc>) {
129-
let s_str = s.as_str();
130-
let str_global = *self.const_str_cache.borrow_mut().entry(s).or_insert_with(|| {
131-
self.global_string(s_str)
132-
});
133-
let len = s_str.len();
127+
fn const_str(&self, s: &str) -> (RValue<'gcc>, RValue<'gcc>) {
128+
let str_global = *self
129+
.const_str_cache
130+
.borrow_mut()
131+
.raw_entry_mut()
132+
.from_key(s)
133+
.or_insert_with(|| (s.to_owned(), self.global_string(s)))
134+
.1;
135+
let len = s.len();
134136
let cs = self.const_ptrcast(str_global.get_address(None),
135137
self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self, true)),
136138
);

src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::mono::CodegenUnit;
1313
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1414
use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout, LayoutOfHelpers};
1515
use rustc_session::Session;
16-
use rustc_span::{Span, Symbol};
16+
use rustc_span::Span;
1717
use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
1818
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
1919

@@ -101,7 +101,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
101101
pub global_lvalues: RefCell<FxHashMap<RValue<'gcc>, LValue<'gcc>>>,
102102

103103
/// Cache of constant strings,
104-
pub const_str_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>,
104+
pub const_str_cache: RefCell<FxHashMap<String, LValue<'gcc>>>,
105105

106106
/// Cache of globals.
107107
pub globals: RefCell<FxHashMap<String, RValue<'gcc>>>,

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
* TODO(antoyo): remove the patches.
77
*/
88

9-
#![feature(rustc_private, decl_macro, associated_type_bounds, never_type, trusted_len)]
9+
#![feature(
10+
rustc_private,
11+
decl_macro,
12+
associated_type_bounds,
13+
never_type,
14+
trusted_len,
15+
hash_raw_entry
16+
)]
1017
#![allow(broken_intra_doc_links)]
1118
#![recursion_limit="256"]
1219
#![warn(rust_2018_idioms)]

0 commit comments

Comments
 (0)