Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a specialized string interner to reduce the need for owned strings #6356

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ pub fn exported_name(sess: Session,
vers: &str) -> ~str {
return mangle(sess,
vec::append_one(
vec::append_one(path, path_name(sess.ident_of(hash.to_owned()))),
path_name(sess.ident_of(vers.to_owned()))));
vec::append_one(path, path_name(sess.ident_of(hash))),
path_name(sess.ident_of(vers))));
}

pub fn mangle_exported_name(ccx: @CrateContext,
Expand All @@ -717,14 +717,14 @@ pub fn mangle_internal_name_by_type_only(ccx: @CrateContext,
let s = ppaux::ty_to_short_str(ccx.tcx, t);
let hash = get_symbol_hash(ccx, t);
return mangle(ccx.sess,
~[path_name(ccx.sess.ident_of(name.to_owned())),
~[path_name(ccx.sess.ident_of(name)),
path_name(ccx.sess.ident_of(s)),
path_name(ccx.sess.ident_of(hash.to_owned()))]);
path_name(ccx.sess.ident_of(hash))]);
}

pub fn mangle_internal_name_by_path_and_seq(ccx: @CrateContext,
path: path,
flav: ~str) -> ~str {
flav: &str) -> ~str {
return mangle(ccx.sess,
vec::append_one(path, path_name((ccx.names)(flav))));
}
Expand All @@ -733,7 +733,7 @@ pub fn mangle_internal_name_by_path(ccx: @CrateContext, path: path) -> ~str {
return mangle(ccx.sess, path);
}

pub fn mangle_internal_name_by_seq(ccx: @CrateContext, flav: ~str) -> ~str {
pub fn mangle_internal_name_by_seq(ccx: @CrateContext, flav: &str) -> ~str {
return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ pub impl Session_ {
fn str_of(@self, id: ast::ident) -> @~str {
self.parse_sess.interner.get(id)
}
fn ident_of(@self, st: ~str) -> ast::ident {
self.parse_sess.interner.intern(@st)
fn ident_of(@self, st: &str) -> ast::ident {
self.parse_sess.interner.intern(st)
}
fn intr(@self) -> @syntax::parse::token::ident_interner {
self.parse_sess.interner
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/front/core_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn inject_libcore_ref(sess: Session,
let n1 = sess.next_node_id();
let vi1 = @ast::view_item {
node: ast::view_item_extern_mod(
sess.ident_of(~"core"), ~[], n1),
sess.ident_of("core"), ~[], n1),
attrs: ~[
spanned(ast::attribute_ {
style: ast::attr_inner,
Expand Down Expand Up @@ -78,8 +78,8 @@ fn inject_libcore_ref(sess: Session,
span: dummy_sp(),
global: false,
idents: ~[
sess.ident_of(~"core"),
sess.ident_of(~"prelude")
sess.ident_of("core"),
sess.ident_of("prelude")
],
rp: None,
types: ~[]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn mk_std(cx: &TestCtxt) -> @ast::view_item {
let vers = nospan(vers);
let mi = ast::meta_name_value(@~"vers", vers);
let mi = nospan(mi);
let id_std = cx.sess.ident_of(~"std");
let id_std = cx.sess.ident_of("std");
let vi = if is_std(cx) {
ast::view_item_use(
~[@nospan(ast::view_path_simple(id_std,
Expand Down Expand Up @@ -322,7 +322,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
attr::mk_attr(attr::mk_word_item(@~"!resolve_unexported"));

let item = ast::item {
ident: cx.sess.ident_of(~"__test"),
ident: cx.sess.ident_of("__test"),
attrs: ~[resolve_unexported_attr],
id: cx.sess.next_node_id(),
node: item_,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
// FIXME #1920: This path is not always correct if the crate is not linked
// into the root namespace.
vec::append(~[ast_map::path_mod(tcx.sess.ident_of(
/*bad*/copy *cdata.name))], path)
*cdata.name))], path)
}

pub enum found_ast {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ fn item_path(intr: @ident_interner, item_doc: ebml::Doc) -> ast_map::path {
for reader::docs(path_doc) |tag, elt_doc| {
if tag == tag_path_elt_mod {
let str = reader::doc_as_str(elt_doc);
result.push(ast_map::path_mod(intr.intern(@str)));
result.push(ast_map::path_mod(intr.intern(str)));
} else if tag == tag_path_elt_name {
let str = reader::doc_as_str(elt_doc);
result.push(ast_map::path_name(intr.intern(@str)));
result.push(ast_map::path_name(intr.intern(str)));
} else {
// ignore tag_path_len element
}
Expand All @@ -311,7 +311,7 @@ fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::ident {
do reader::with_doc_data(name) |data| {
let string = str::from_bytes_slice(data);
match intr.find_equiv(&StringRef(string)) {
None => intr.intern(@(string.to_owned())),
None => intr.intern(string),
Some(val) => val,
}
}
Expand Down Expand Up @@ -828,7 +828,7 @@ pub fn get_type_name_if_impl(intr: @ident_interner,
}

for reader::tagged_docs(item, tag_item_impl_type_basename) |doc| {
return Some(intr.intern(@str::from_bytes(reader::doc_data(doc))));
return Some(intr.intern(str::from_bytes(reader::doc_data(doc))));
}

return None;
Expand Down Expand Up @@ -1080,7 +1080,7 @@ pub fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] {
}
for reader::tagged_docs(depsdoc, tag_crate_dep) |depdoc| {
deps.push(crate_dep {cnum: crate_num,
name: intr.intern(@docstr(depdoc, tag_crate_dep_name)),
name: intr.intern(docstr(depdoc, tag_crate_dep_name)),
vers: @docstr(depdoc, tag_crate_dep_vers),
hash: @docstr(depdoc, tag_crate_dep_hash)});
crate_num += 1;
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ trait fake_ext_ctxt {
fn cfg(&self) -> ast::crate_cfg;
fn parse_sess(&self) -> @mut parse::ParseSess;
fn call_site(&self) -> span;
fn ident_of(&self, st: ~str) -> ast::ident;
fn ident_of(&self, st: &str) -> ast::ident;
}

#[cfg(test)]
Expand All @@ -1180,8 +1180,8 @@ impl fake_ext_ctxt for fake_session {
expn_info: None
}
}
fn ident_of(&self, st: ~str) -> ast::ident {
self.interner.intern(@st)
fn ident_of(&self, st: &str) -> ast::ident {
self.interner.intern(st)
}
}

Expand Down
36 changes: 18 additions & 18 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ pub struct PrimitiveTypeTable {
}

pub impl PrimitiveTypeTable {
fn intern(&mut self, intr: @ident_interner, string: @~str,
fn intern(&mut self, intr: @ident_interner, string: &str,
primitive_type: prim_ty) {
let ident = intr.intern(string);
self.primitive_types.insert(ident, primitive_type);
Expand All @@ -720,22 +720,22 @@ pub fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
primitive_types: HashMap::new()
};

table.intern(intr, @~"bool", ty_bool);
table.intern(intr, @~"char", ty_int(ty_char));
table.intern(intr, @~"float", ty_float(ty_f));
table.intern(intr, @~"f32", ty_float(ty_f32));
table.intern(intr, @~"f64", ty_float(ty_f64));
table.intern(intr, @~"int", ty_int(ty_i));
table.intern(intr, @~"i8", ty_int(ty_i8));
table.intern(intr, @~"i16", ty_int(ty_i16));
table.intern(intr, @~"i32", ty_int(ty_i32));
table.intern(intr, @~"i64", ty_int(ty_i64));
table.intern(intr, @~"str", ty_str);
table.intern(intr, @~"uint", ty_uint(ty_u));
table.intern(intr, @~"u8", ty_uint(ty_u8));
table.intern(intr, @~"u16", ty_uint(ty_u16));
table.intern(intr, @~"u32", ty_uint(ty_u32));
table.intern(intr, @~"u64", ty_uint(ty_u64));
table.intern(intr, "bool", ty_bool);
table.intern(intr, "char", ty_int(ty_char));
table.intern(intr, "float", ty_float(ty_f));
table.intern(intr, "f32", ty_float(ty_f32));
table.intern(intr, "f64", ty_float(ty_f64));
table.intern(intr, "int", ty_int(ty_i));
table.intern(intr, "i8", ty_int(ty_i8));
table.intern(intr, "i16", ty_int(ty_i16));
table.intern(intr, "i32", ty_int(ty_i32));
table.intern(intr, "i64", ty_int(ty_i64));
table.intern(intr, "str", ty_str);
table.intern(intr, "uint", ty_uint(ty_u));
table.intern(intr, "u8", ty_uint(ty_u8));
table.intern(intr, "u16", ty_uint(ty_u16));
table.intern(intr, "u32", ty_uint(ty_u32));
table.intern(intr, "u64", ty_uint(ty_u64));

return table;
}
Expand Down Expand Up @@ -1675,7 +1675,7 @@ pub impl Resolver {

let mut current_module = root;
for pieces.each |ident_str| {
let ident = self.session.ident_of(/*bad*/copy *ident_str);
let ident = self.session.ident_of(*ident_str);
// Create or reuse a graph node for the child.
let (child_name_bindings, new_parent) =
self.add_child(ident,
Expand Down
34 changes: 17 additions & 17 deletions src/librustc/middle/resolve_stage0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ pub struct PrimitiveTypeTable {
}

pub impl PrimitiveTypeTable {
fn intern(&mut self, intr: @ident_interner, string: @~str,
fn intern(&mut self, intr: @ident_interner, string: &str,
primitive_type: prim_ty) {
let ident = intr.intern(string);
self.primitive_types.insert(ident, primitive_type);
Expand All @@ -721,22 +721,22 @@ pub fn PrimitiveTypeTable(intr: @ident_interner) -> PrimitiveTypeTable {
primitive_types: HashMap::new()
};

table.intern(intr, @~"bool", ty_bool);
table.intern(intr, @~"char", ty_int(ty_char));
table.intern(intr, @~"float", ty_float(ty_f));
table.intern(intr, @~"f32", ty_float(ty_f32));
table.intern(intr, @~"f64", ty_float(ty_f64));
table.intern(intr, @~"int", ty_int(ty_i));
table.intern(intr, @~"i8", ty_int(ty_i8));
table.intern(intr, @~"i16", ty_int(ty_i16));
table.intern(intr, @~"i32", ty_int(ty_i32));
table.intern(intr, @~"i64", ty_int(ty_i64));
table.intern(intr, @~"str", ty_str);
table.intern(intr, @~"uint", ty_uint(ty_u));
table.intern(intr, @~"u8", ty_uint(ty_u8));
table.intern(intr, @~"u16", ty_uint(ty_u16));
table.intern(intr, @~"u32", ty_uint(ty_u32));
table.intern(intr, @~"u64", ty_uint(ty_u64));
table.intern(intr, "bool", ty_bool);
table.intern(intr, "char", ty_int(ty_char));
table.intern(intr, "float", ty_float(ty_f));
table.intern(intr, "f32", ty_float(ty_f32));
table.intern(intr, "f64", ty_float(ty_f64));
table.intern(intr, "int", ty_int(ty_i));
table.intern(intr, "i8", ty_int(ty_i8));
table.intern(intr, "i16", ty_int(ty_i16));
table.intern(intr, "i32", ty_int(ty_i32));
table.intern(intr, "i64", ty_int(ty_i64));
table.intern(intr, "str", ty_str);
table.intern(intr, "uint", ty_uint(ty_u));
table.intern(intr, "u8", ty_uint(ty_u8));
table.intern(intr, "u16", ty_uint(ty_u16));
table.intern(intr, "u32", ty_uint(ty_u32));
table.intern(intr, "u64", ty_uint(ty_u64));

return table;
}
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ pub fn compile_guard(bcx: block,

let val = unpack_result!(bcx, {
do with_scope_result(bcx, guard_expr.info(),
~"guard") |bcx| {
"guard") |bcx| {
expr::trans_to_datum(bcx, guard_expr).to_result()
}
});
Expand Down Expand Up @@ -1446,7 +1446,7 @@ pub fn compile_submatch(bcx: block,
}
let else_cx = match kind {
no_branch | single => bcx,
_ => sub_block(bcx, ~"match_else")
_ => sub_block(bcx, "match_else")
};
let sw = if kind == switch {
Switch(bcx, test_val, else_cx.llbb, opts.len())
Expand All @@ -1464,7 +1464,7 @@ pub fn compile_submatch(bcx: block,
i += 1u;
let mut opt_cx = else_cx;
if !exhaustive || i < len {
opt_cx = sub_block(bcx, ~"match_case");
opt_cx = sub_block(bcx, "match_case");
match kind {
single => Br(bcx, opt_cx.llbb),
switch => {
Expand All @@ -1486,7 +1486,7 @@ pub fn compile_submatch(bcx: block,
let t = node_id_type(bcx, pat_id);
let Result {bcx: after_cx, val: matches} = {
do with_scope_result(bcx, None,
~"compare_scope") |bcx| {
"compare_scope") |bcx| {
match trans_opt(bcx, opt) {
single_result(
Result {bcx, val}) => {
Expand Down Expand Up @@ -1514,13 +1514,13 @@ pub fn compile_submatch(bcx: block,
}
}
};
bcx = sub_block(after_cx, ~"compare_next");
bcx = sub_block(after_cx, "compare_next");
CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb);
}
compare_vec_len => {
let Result {bcx: after_cx, val: matches} = {
do with_scope_result(bcx, None,
~"compare_vec_len_scope") |bcx| {
"compare_vec_len_scope") |bcx| {
match trans_opt(bcx, opt) {
single_result(
Result {bcx, val}) => {
Expand Down Expand Up @@ -1552,7 +1552,7 @@ pub fn compile_submatch(bcx: block,
}
}
};
bcx = sub_block(after_cx, ~"compare_vec_len_next");
bcx = sub_block(after_cx, "compare_vec_len_next");
CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb);
}
_ => ()
Expand Down Expand Up @@ -1610,7 +1610,7 @@ pub fn trans_match(bcx: block,
arms: ~[ast::arm],
dest: Dest) -> block {
let _icx = bcx.insn_ctxt("match::trans_match");
do with_scope(bcx, match_expr.info(), ~"match") |bcx| {
do with_scope(bcx, match_expr.info(), "match") |bcx| {
trans_match_inner(bcx, discr_expr, arms, dest)
}
}
Expand All @@ -1632,7 +1632,7 @@ pub fn trans_match_inner(scope_cx: block,

let mut arm_datas = ~[], matches = ~[];
for arms.each |arm| {
let body = scope_block(bcx, arm.body.info(), ~"case_body");
let body = scope_block(bcx, arm.body.info(), "case_body");

// Create the bindings map, which is a mapping from each binding name
// to an alloca() that will be the value for that local variable.
Expand Down Expand Up @@ -1716,7 +1716,7 @@ pub fn trans_match_inner(scope_cx: block,
fn mk_fail(bcx: block, sp: span, msg: @~str,
finished: @mut Option<BasicBlockRef>) -> BasicBlockRef {
match *finished { Some(bb) => return bb, _ => () }
let fail_cx = sub_block(bcx, ~"case_fallthrough");
let fail_cx = sub_block(bcx, "case_fallthrough");
controlflow::trans_fail(fail_cx, Some(sp), msg);
*finished = Some(fail_cx.llbb);
return fail_cx.llbb;
Expand Down
Loading