Skip to content

Commit e9d0018

Browse files
committed
auto merge of #6356 : dotdash/rust/strinterner, r=pcwalton
&str can be turned into @~str on demand, using to_owned(), so for strings, we can create a specialized interner that accepts &str for intern() and find() but stores and returns @~str.
2 parents f04eb37 + 1393c3a commit e9d0018

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+521
-466
lines changed

src/librustc/back/link.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ pub fn exported_name(sess: Session,
698698
vers: &str) -> ~str {
699699
return mangle(sess,
700700
vec::append_one(
701-
vec::append_one(path, path_name(sess.ident_of(hash.to_owned()))),
702-
path_name(sess.ident_of(vers.to_owned()))));
701+
vec::append_one(path, path_name(sess.ident_of(hash))),
702+
path_name(sess.ident_of(vers))));
703703
}
704704
705705
pub fn mangle_exported_name(ccx: @CrateContext,
@@ -717,14 +717,14 @@ pub fn mangle_internal_name_by_type_only(ccx: @CrateContext,
717717
let s = ppaux::ty_to_short_str(ccx.tcx, t);
718718
let hash = get_symbol_hash(ccx, t);
719719
return mangle(ccx.sess,
720-
~[path_name(ccx.sess.ident_of(name.to_owned())),
720+
~[path_name(ccx.sess.ident_of(name)),
721721
path_name(ccx.sess.ident_of(s)),
722-
path_name(ccx.sess.ident_of(hash.to_owned()))]);
722+
path_name(ccx.sess.ident_of(hash))]);
723723
}
724724
725725
pub fn mangle_internal_name_by_path_and_seq(ccx: @CrateContext,
726726
path: path,
727-
flav: ~str) -> ~str {
727+
flav: &str) -> ~str {
728728
return mangle(ccx.sess,
729729
vec::append_one(path, path_name((ccx.names)(flav))));
730730
}
@@ -733,7 +733,7 @@ pub fn mangle_internal_name_by_path(ccx: @CrateContext, path: path) -> ~str {
733733
return mangle(ccx.sess, path);
734734
}
735735
736-
pub fn mangle_internal_name_by_seq(ccx: @CrateContext, flav: ~str) -> ~str {
736+
pub fn mangle_internal_name_by_seq(ccx: @CrateContext, flav: &str) -> ~str {
737737
return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
738738
}
739739

src/librustc/driver/session.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ pub impl Session_ {
285285
fn str_of(@self, id: ast::ident) -> @~str {
286286
self.parse_sess.interner.get(id)
287287
}
288-
fn ident_of(@self, st: ~str) -> ast::ident {
289-
self.parse_sess.interner.intern(@st)
288+
fn ident_of(@self, st: &str) -> ast::ident {
289+
self.parse_sess.interner.intern(st)
290290
}
291291
fn intr(@self) -> @syntax::parse::token::ident_interner {
292292
self.parse_sess.interner

src/librustc/front/core_inject.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn inject_libcore_ref(sess: Session,
4242
let n1 = sess.next_node_id();
4343
let vi1 = @ast::view_item {
4444
node: ast::view_item_extern_mod(
45-
sess.ident_of(~"core"), ~[], n1),
45+
sess.ident_of("core"), ~[], n1),
4646
attrs: ~[
4747
spanned(ast::attribute_ {
4848
style: ast::attr_inner,
@@ -78,8 +78,8 @@ fn inject_libcore_ref(sess: Session,
7878
span: dummy_sp(),
7979
global: false,
8080
idents: ~[
81-
sess.ident_of(~"core"),
82-
sess.ident_of(~"prelude")
81+
sess.ident_of("core"),
82+
sess.ident_of("prelude")
8383
],
8484
rp: None,
8585
types: ~[]

src/librustc/front/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn mk_std(cx: &TestCtxt) -> @ast::view_item {
274274
let vers = nospan(vers);
275275
let mi = ast::meta_name_value(@~"vers", vers);
276276
let mi = nospan(mi);
277-
let id_std = cx.sess.ident_of(~"std");
277+
let id_std = cx.sess.ident_of("std");
278278
let vi = if is_std(cx) {
279279
ast::view_item_use(
280280
~[@nospan(ast::view_path_simple(id_std,
@@ -322,7 +322,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
322322
attr::mk_attr(attr::mk_word_item(@~"!resolve_unexported"));
323323

324324
let item = ast::item {
325-
ident: cx.sess.ident_of(~"__test"),
325+
ident: cx.sess.ident_of("__test"),
326326
attrs: ~[resolve_unexported_attr],
327327
id: cx.sess.next_node_id(),
328328
node: item_,

src/librustc/metadata/csearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
7070
// FIXME #1920: This path is not always correct if the crate is not linked
7171
// into the root namespace.
7272
vec::append(~[ast_map::path_mod(tcx.sess.ident_of(
73-
/*bad*/copy *cdata.name))], path)
73+
*cdata.name))], path)
7474
}
7575

7676
pub enum found_ast {

src/librustc/metadata/decoder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ fn item_path(intr: @ident_interner, item_doc: ebml::Doc) -> ast_map::path {
294294
for reader::docs(path_doc) |tag, elt_doc| {
295295
if tag == tag_path_elt_mod {
296296
let str = reader::doc_as_str(elt_doc);
297-
result.push(ast_map::path_mod(intr.intern(@str)));
297+
result.push(ast_map::path_mod(intr.intern(str)));
298298
} else if tag == tag_path_elt_name {
299299
let str = reader::doc_as_str(elt_doc);
300-
result.push(ast_map::path_name(intr.intern(@str)));
300+
result.push(ast_map::path_name(intr.intern(str)));
301301
} else {
302302
// ignore tag_path_len element
303303
}
@@ -311,7 +311,7 @@ fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::ident {
311311
do reader::with_doc_data(name) |data| {
312312
let string = str::from_bytes_slice(data);
313313
match intr.find_equiv(&StringRef(string)) {
314-
None => intr.intern(@(string.to_owned())),
314+
None => intr.intern(string),
315315
Some(val) => val,
316316
}
317317
}
@@ -828,7 +828,7 @@ pub fn get_type_name_if_impl(intr: @ident_interner,
828828
}
829829

830830
for reader::tagged_docs(item, tag_item_impl_type_basename) |doc| {
831-
return Some(intr.intern(@str::from_bytes(reader::doc_data(doc))));
831+
return Some(intr.intern(str::from_bytes(reader::doc_data(doc))));
832832
}
833833

834834
return None;
@@ -1080,7 +1080,7 @@ pub fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] {
10801080
}
10811081
for reader::tagged_docs(depsdoc, tag_crate_dep) |depdoc| {
10821082
deps.push(crate_dep {cnum: crate_num,
1083-
name: intr.intern(@docstr(depdoc, tag_crate_dep_name)),
1083+
name: intr.intern(docstr(depdoc, tag_crate_dep_name)),
10841084
vers: @docstr(depdoc, tag_crate_dep_vers),
10851085
hash: @docstr(depdoc, tag_crate_dep_hash)});
10861086
crate_num += 1;

src/librustc/middle/astencode.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ trait fake_ext_ctxt {
11631163
fn cfg(&self) -> ast::crate_cfg;
11641164
fn parse_sess(&self) -> @mut parse::ParseSess;
11651165
fn call_site(&self) -> span;
1166-
fn ident_of(&self, st: ~str) -> ast::ident;
1166+
fn ident_of(&self, st: &str) -> ast::ident;
11671167
}
11681168

11691169
#[cfg(test)]
@@ -1180,8 +1180,8 @@ impl fake_ext_ctxt for fake_session {
11801180
expn_info: None
11811181
}
11821182
}
1183-
fn ident_of(&self, st: ~str) -> ast::ident {
1184-
self.interner.intern(@st)
1183+
fn ident_of(&self, st: &str) -> ast::ident {
1184+
self.interner.intern(st)
11851185
}
11861186
}
11871187

src/librustc/middle/resolve.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ pub struct PrimitiveTypeTable {
708708
}
709709
710710
pub impl PrimitiveTypeTable {
711-
fn intern(&mut self, intr: @ident_interner, string: @~str,
711+
fn intern(&mut self, intr: @ident_interner, string: &str,
712712
primitive_type: prim_ty) {
713713
let ident = intr.intern(string);
714714
self.primitive_types.insert(ident, primitive_type);
@@ -720,22 +720,22 @@ pub fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
720720
primitive_types: HashMap::new()
721721
};
722722
723-
table.intern(intr, @~"bool", ty_bool);
724-
table.intern(intr, @~"char", ty_int(ty_char));
725-
table.intern(intr, @~"float", ty_float(ty_f));
726-
table.intern(intr, @~"f32", ty_float(ty_f32));
727-
table.intern(intr, @~"f64", ty_float(ty_f64));
728-
table.intern(intr, @~"int", ty_int(ty_i));
729-
table.intern(intr, @~"i8", ty_int(ty_i8));
730-
table.intern(intr, @~"i16", ty_int(ty_i16));
731-
table.intern(intr, @~"i32", ty_int(ty_i32));
732-
table.intern(intr, @~"i64", ty_int(ty_i64));
733-
table.intern(intr, @~"str", ty_str);
734-
table.intern(intr, @~"uint", ty_uint(ty_u));
735-
table.intern(intr, @~"u8", ty_uint(ty_u8));
736-
table.intern(intr, @~"u16", ty_uint(ty_u16));
737-
table.intern(intr, @~"u32", ty_uint(ty_u32));
738-
table.intern(intr, @~"u64", ty_uint(ty_u64));
723+
table.intern(intr, "bool", ty_bool);
724+
table.intern(intr, "char", ty_int(ty_char));
725+
table.intern(intr, "float", ty_float(ty_f));
726+
table.intern(intr, "f32", ty_float(ty_f32));
727+
table.intern(intr, "f64", ty_float(ty_f64));
728+
table.intern(intr, "int", ty_int(ty_i));
729+
table.intern(intr, "i8", ty_int(ty_i8));
730+
table.intern(intr, "i16", ty_int(ty_i16));
731+
table.intern(intr, "i32", ty_int(ty_i32));
732+
table.intern(intr, "i64", ty_int(ty_i64));
733+
table.intern(intr, "str", ty_str);
734+
table.intern(intr, "uint", ty_uint(ty_u));
735+
table.intern(intr, "u8", ty_uint(ty_u8));
736+
table.intern(intr, "u16", ty_uint(ty_u16));
737+
table.intern(intr, "u32", ty_uint(ty_u32));
738+
table.intern(intr, "u64", ty_uint(ty_u64));
739739
740740
return table;
741741
}
@@ -1675,7 +1675,7 @@ pub impl Resolver {
16751675

16761676
let mut current_module = root;
16771677
for pieces.each |ident_str| {
1678-
let ident = self.session.ident_of(/*bad*/copy *ident_str);
1678+
let ident = self.session.ident_of(*ident_str);
16791679
// Create or reuse a graph node for the child.
16801680
let (child_name_bindings, new_parent) =
16811681
self.add_child(ident,

src/librustc/middle/resolve_stage0.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ pub struct PrimitiveTypeTable {
709709
}
710710
711711
pub impl PrimitiveTypeTable {
712-
fn intern(&mut self, intr: @ident_interner, string: @~str,
712+
fn intern(&mut self, intr: @ident_interner, string: &str,
713713
primitive_type: prim_ty) {
714714
let ident = intr.intern(string);
715715
self.primitive_types.insert(ident, primitive_type);
@@ -721,22 +721,22 @@ pub fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
721721
primitive_types: HashMap::new()
722722
};
723723
724-
table.intern(intr, @~"bool", ty_bool);
725-
table.intern(intr, @~"char", ty_int(ty_char));
726-
table.intern(intr, @~"float", ty_float(ty_f));
727-
table.intern(intr, @~"f32", ty_float(ty_f32));
728-
table.intern(intr, @~"f64", ty_float(ty_f64));
729-
table.intern(intr, @~"int", ty_int(ty_i));
730-
table.intern(intr, @~"i8", ty_int(ty_i8));
731-
table.intern(intr, @~"i16", ty_int(ty_i16));
732-
table.intern(intr, @~"i32", ty_int(ty_i32));
733-
table.intern(intr, @~"i64", ty_int(ty_i64));
734-
table.intern(intr, @~"str", ty_str);
735-
table.intern(intr, @~"uint", ty_uint(ty_u));
736-
table.intern(intr, @~"u8", ty_uint(ty_u8));
737-
table.intern(intr, @~"u16", ty_uint(ty_u16));
738-
table.intern(intr, @~"u32", ty_uint(ty_u32));
739-
table.intern(intr, @~"u64", ty_uint(ty_u64));
724+
table.intern(intr, "bool", ty_bool);
725+
table.intern(intr, "char", ty_int(ty_char));
726+
table.intern(intr, "float", ty_float(ty_f));
727+
table.intern(intr, "f32", ty_float(ty_f32));
728+
table.intern(intr, "f64", ty_float(ty_f64));
729+
table.intern(intr, "int", ty_int(ty_i));
730+
table.intern(intr, "i8", ty_int(ty_i8));
731+
table.intern(intr, "i16", ty_int(ty_i16));
732+
table.intern(intr, "i32", ty_int(ty_i32));
733+
table.intern(intr, "i64", ty_int(ty_i64));
734+
table.intern(intr, "str", ty_str);
735+
table.intern(intr, "uint", ty_uint(ty_u));
736+
table.intern(intr, "u8", ty_uint(ty_u8));
737+
table.intern(intr, "u16", ty_uint(ty_u16));
738+
table.intern(intr, "u32", ty_uint(ty_u32));
739+
table.intern(intr, "u64", ty_uint(ty_u64));
740740
741741
return table;
742742
}

src/librustc/middle/trans/_match.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ pub fn compile_guard(bcx: block,
12231223
12241224
let val = unpack_result!(bcx, {
12251225
do with_scope_result(bcx, guard_expr.info(),
1226-
~"guard") |bcx| {
1226+
"guard") |bcx| {
12271227
expr::trans_to_datum(bcx, guard_expr).to_result()
12281228
}
12291229
});
@@ -1447,7 +1447,7 @@ pub fn compile_submatch(bcx: block,
14471447
}
14481448
let else_cx = match kind {
14491449
no_branch | single => bcx,
1450-
_ => sub_block(bcx, ~"match_else")
1450+
_ => sub_block(bcx, "match_else")
14511451
};
14521452
let sw = if kind == switch {
14531453
Switch(bcx, test_val, else_cx.llbb, opts.len())
@@ -1465,7 +1465,7 @@ pub fn compile_submatch(bcx: block,
14651465
i += 1u;
14661466
let mut opt_cx = else_cx;
14671467
if !exhaustive || i < len {
1468-
opt_cx = sub_block(bcx, ~"match_case");
1468+
opt_cx = sub_block(bcx, "match_case");
14691469
match kind {
14701470
single => Br(bcx, opt_cx.llbb),
14711471
switch => {
@@ -1487,7 +1487,7 @@ pub fn compile_submatch(bcx: block,
14871487
let t = node_id_type(bcx, pat_id);
14881488
let Result {bcx: after_cx, val: matches} = {
14891489
do with_scope_result(bcx, None,
1490-
~"compare_scope") |bcx| {
1490+
"compare_scope") |bcx| {
14911491
match trans_opt(bcx, opt) {
14921492
single_result(
14931493
Result {bcx, val}) => {
@@ -1515,13 +1515,13 @@ pub fn compile_submatch(bcx: block,
15151515
}
15161516
}
15171517
};
1518-
bcx = sub_block(after_cx, ~"compare_next");
1518+
bcx = sub_block(after_cx, "compare_next");
15191519
CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb);
15201520
}
15211521
compare_vec_len => {
15221522
let Result {bcx: after_cx, val: matches} = {
15231523
do with_scope_result(bcx, None,
1524-
~"compare_vec_len_scope") |bcx| {
1524+
"compare_vec_len_scope") |bcx| {
15251525
match trans_opt(bcx, opt) {
15261526
single_result(
15271527
Result {bcx, val}) => {
@@ -1553,7 +1553,7 @@ pub fn compile_submatch(bcx: block,
15531553
}
15541554
}
15551555
};
1556-
bcx = sub_block(after_cx, ~"compare_vec_len_next");
1556+
bcx = sub_block(after_cx, "compare_vec_len_next");
15571557
CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb);
15581558
}
15591559
_ => ()
@@ -1611,7 +1611,7 @@ pub fn trans_match(bcx: block,
16111611
arms: ~[ast::arm],
16121612
dest: Dest) -> block {
16131613
let _icx = bcx.insn_ctxt("match::trans_match");
1614-
do with_scope(bcx, match_expr.info(), ~"match") |bcx| {
1614+
do with_scope(bcx, match_expr.info(), "match") |bcx| {
16151615
trans_match_inner(bcx, discr_expr, arms, dest)
16161616
}
16171617
}
@@ -1633,7 +1633,7 @@ pub fn trans_match_inner(scope_cx: block,
16331633
16341634
let mut arm_datas = ~[], matches = ~[];
16351635
for arms.each |arm| {
1636-
let body = scope_block(bcx, arm.body.info(), ~"case_body");
1636+
let body = scope_block(bcx, arm.body.info(), "case_body");
16371637
16381638
// Create the bindings map, which is a mapping from each binding name
16391639
// to an alloca() that will be the value for that local variable.
@@ -1717,7 +1717,7 @@ pub fn trans_match_inner(scope_cx: block,
17171717
fn mk_fail(bcx: block, sp: span, msg: @~str,
17181718
finished: @mut Option<BasicBlockRef>) -> BasicBlockRef {
17191719
match *finished { Some(bb) => return bb, _ => () }
1720-
let fail_cx = sub_block(bcx, ~"case_fallthrough");
1720+
let fail_cx = sub_block(bcx, "case_fallthrough");
17211721
controlflow::trans_fail(fail_cx, Some(sp), msg);
17221722
*finished = Some(fail_cx.llbb);
17231723
return fail_cx.llbb;

0 commit comments

Comments
 (0)