Convert portions of rustc to istrs. Recover a lot of performance.
Issue #855
This commit is contained in:
parent
fcc031c5b4
commit
b2408d57f0
@ -412,7 +412,7 @@ fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: &link_meta) ->
|
||||
// FIXME: This wants to be link_meta.meta_hash
|
||||
sha.input_str(istr::from_estr(link_meta.name));
|
||||
sha.input_str(~"-");
|
||||
sha.input_str(istr::from_estr(encoder::encoded_ty(tcx, t)));
|
||||
sha.input_str(encoder::encoded_ty(tcx, t));
|
||||
let hash = truncated_sha1_result(sha);
|
||||
// Prefix with _ so that it never blends into adjacent digits
|
||||
|
||||
@ -458,7 +458,7 @@ fn mangle_internal_name_by_type_only(ccx: &@crate_ctxt, t: ty::t, name: &str)
|
||||
-> str {
|
||||
let s = util::ppaux::ty_to_short_str(ccx.tcx, t);
|
||||
let hash = get_symbol_hash(ccx, t);
|
||||
ret mangle([name, s, hash]);
|
||||
ret mangle([name, istr::to_estr(s), hash]);
|
||||
}
|
||||
|
||||
fn mangle_internal_name_by_path_and_seq(ccx: &@crate_ctxt, path: &[str],
|
||||
|
@ -1,6 +1,6 @@
|
||||
// EBML tag definitions and utils shared by the encoder and decoder
|
||||
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
const tag_paths: uint = 0x01u;
|
||||
|
||||
@ -67,9 +67,9 @@ const tag_items_data_item_inlineness: uint = 0x27u;
|
||||
// djb's cdb hashes.
|
||||
fn hash_node_id(node_id: &int) -> uint { ret 177573u ^ (node_id as uint); }
|
||||
|
||||
fn hash_path(s: &str) -> uint {
|
||||
fn hash_path(s: &istr) -> uint {
|
||||
let h = 5381u;
|
||||
for ch: u8 in str::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
|
||||
for ch: u8 in istr::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
|
||||
ret h;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,8 @@ fn resolve_path(path: &[ast::ident], data: @[u8]) -> [ast::def_id] {
|
||||
let paths = ebml::get_doc(md, tag_paths);
|
||||
let eqer = bind eq_item(_, s);
|
||||
let result: [ast::def_id] = [];
|
||||
for doc: ebml::doc in lookup_hash(paths, eqer, hash_path(s)) {
|
||||
for doc: ebml::doc in lookup_hash(paths, eqer,
|
||||
hash_path(istr::from_estr(s))) {
|
||||
let did_doc = ebml::get_doc(doc, tag_def_id);
|
||||
result += [parse_def_id(ebml::doc_data(did_doc))];
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
|
||||
type encode_ctxt = {ccx: @crate_ctxt, type_abbrevs: abbrev_map};
|
||||
|
||||
// Path table encoding
|
||||
fn encode_name(ebml_w: &ebml::writer, name: &str) {
|
||||
fn encode_name(ebml_w: &ebml::writer, name: &istr) {
|
||||
ebml::start_tag(ebml_w, tag_paths_data_name);
|
||||
ebml_w.writer.write(str::bytes(name));
|
||||
ebml_w.writer.write(istr::bytes(name));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
@ -42,107 +42,111 @@ fn encode_def_id(ebml_w: &ebml::writer, id: &def_id) {
|
||||
type entry<T> = {val: T, pos: uint};
|
||||
|
||||
fn encode_tag_variant_paths(ebml_w: &ebml::writer, variants: &[variant],
|
||||
path: &[str], index: &mutable [entry<str>]) {
|
||||
path: &[istr], index: &mutable [entry<istr>]) {
|
||||
for variant: variant in variants {
|
||||
add_to_index(ebml_w, path, index, variant.node.name);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(variant.node.name));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, variant.node.name);
|
||||
encode_name(ebml_w, istr::from_estr(variant.node.name));
|
||||
encode_def_id(ebml_w, local_def(variant.node.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
|
||||
fn add_to_index(ebml_w: &ebml::writer, path: &[str],
|
||||
index: &mutable [entry<str>], name: &str) {
|
||||
fn add_to_index(ebml_w: &ebml::writer, path: &[istr],
|
||||
index: &mutable [entry<istr>], name: &istr) {
|
||||
let full_path = path + [name];
|
||||
index +=
|
||||
[{val: str::connect(full_path, "::"), pos: ebml_w.writer.tell()}];
|
||||
[{val: istr::connect(full_path, ~"::"), pos: ebml_w.writer.tell()}];
|
||||
}
|
||||
|
||||
fn encode_native_module_item_paths(ebml_w: &ebml::writer, nmod: &native_mod,
|
||||
path: &[str],
|
||||
index: &mutable [entry<str>]) {
|
||||
path: &[istr],
|
||||
index: &mutable [entry<istr>]) {
|
||||
for nitem: @native_item in nmod.items {
|
||||
add_to_index(ebml_w, path, index, nitem.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(nitem.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, nitem.ident);
|
||||
encode_name(ebml_w, istr::from_estr(nitem.ident));
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod,
|
||||
path: &[str], index: &mutable [entry<str>]) {
|
||||
path: &[istr], index: &mutable [entry<istr>]) {
|
||||
for it: @item in module.items {
|
||||
if !ast_util::is_exported(it.ident, module) { cont; }
|
||||
alt it.node {
|
||||
item_const(_, _) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
item_fn(_, tps) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
item_mod(_mod) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_mod);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
encode_module_item_paths(ebml_w, _mod, path + [it.ident], index);
|
||||
encode_module_item_paths(ebml_w, _mod,
|
||||
path + [istr::from_estr(it.ident)],
|
||||
index);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
item_native_mod(nmod) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_mod);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
encode_native_module_item_paths(ebml_w, nmod, path + [it.ident],
|
||||
index);
|
||||
encode_native_module_item_paths(
|
||||
ebml_w, nmod,
|
||||
path + [istr::from_estr(it.ident)],
|
||||
index);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
item_ty(_, tps) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
item_res(_, _, tps, ctor_id) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
ebml::end_tag(ebml_w);
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
item_tag(variants, tps) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
encode_tag_variant_paths(ebml_w, variants, path, index);
|
||||
}
|
||||
item_obj(_, tps, ctor_id) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
ebml::end_tag(ebml_w);
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
add_to_index(ebml_w, path, index, istr::from_estr(it.ident));
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_name(ebml_w, istr::from_estr(it.ident));
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
@ -150,9 +154,9 @@ fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod,
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_item_paths(ebml_w: &ebml::writer, crate: &@crate) -> [entry<str>] {
|
||||
let index: [entry<str>] = [];
|
||||
let path: [str] = [];
|
||||
fn encode_item_paths(ebml_w: &ebml::writer, crate: &@crate) -> [entry<istr>] {
|
||||
let index: [entry<istr>] = [];
|
||||
let path: [istr] = [];
|
||||
ebml::start_tag(ebml_w, tag_paths);
|
||||
encode_module_item_paths(ebml_w, crate.node.module, path, index);
|
||||
ebml::end_tag(ebml_w);
|
||||
@ -436,8 +440,8 @@ fn encode_index<T>(ebml_w: &ebml::writer, buckets: &[@[entry<T>]],
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn write_str(writer: &io::writer, s: &str) {
|
||||
writer.write_str(istr::from_estr(s));
|
||||
fn write_str(writer: &io::writer, s: &istr) {
|
||||
writer.write_str(s);
|
||||
}
|
||||
|
||||
fn write_int(writer: &io::writer, n: &int) {
|
||||
@ -623,11 +627,11 @@ fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str {
|
||||
}
|
||||
|
||||
// Get the encoded string for a type
|
||||
fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> str {
|
||||
fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> istr {
|
||||
let cx = @{ds: def_to_str, tcx: tcx, abbrevs: tyencode::ac_no_abbrevs};
|
||||
let sw = io::string_writer();
|
||||
tyencode::enc_ty(sw.get_writer(), cx, t);
|
||||
ret istr::to_estr(sw.get_str());
|
||||
ret sw.get_str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ type ctxt =
|
||||
// Compact string representation for ty.t values. API ty_str & parse_from_str.
|
||||
// Extra parameters are for converting to/from def_ids in the string rep.
|
||||
// Whatever format you choose should not contain pipe characters.
|
||||
type ty_abbrev = {pos: uint, len: uint, s: str};
|
||||
type ty_abbrev = {pos: uint, len: uint, s: @istr};
|
||||
|
||||
tag abbrev_ctxt { ac_no_abbrevs; ac_use_abbrevs(hashmap<ty::t, ty_abbrev>); }
|
||||
|
||||
@ -40,21 +40,21 @@ fn cx_uses_abbrevs(cx: &@ctxt) -> bool {
|
||||
fn enc_ty(w: &io::writer, cx: &@ctxt, t: ty::t) {
|
||||
alt cx.abbrevs {
|
||||
ac_no_abbrevs. {
|
||||
let result_str;
|
||||
let result_str: @istr;
|
||||
alt cx.tcx.short_names_cache.find(t) {
|
||||
some(s) { result_str = s; }
|
||||
none. {
|
||||
let sw = io::string_writer();
|
||||
enc_sty(sw.get_writer(), cx, ty::struct(cx.tcx, t));
|
||||
result_str = istr::to_estr(sw.get_str());
|
||||
result_str = @sw.get_str();
|
||||
cx.tcx.short_names_cache.insert(t, result_str);
|
||||
}
|
||||
}
|
||||
w.write_str(istr::from_estr(result_str));
|
||||
w.write_str(*result_str);
|
||||
}
|
||||
ac_use_abbrevs(abbrevs) {
|
||||
alt abbrevs.find(t) {
|
||||
some(a) { w.write_str(istr::from_estr(a.s)); ret; }
|
||||
some(a) { w.write_str(*a.s); ret; }
|
||||
none. {
|
||||
let pos = w.get_buf_writer().tell();
|
||||
enc_sty(w, cx, ty::struct(cx.tcx, t));
|
||||
@ -73,7 +73,7 @@ fn enc_ty(w: &io::writer, cx: &@ctxt, t: ty::t) {
|
||||
let s =
|
||||
~"#" + uint::to_str(pos, 16u) + ~":" +
|
||||
uint::to_str(len, 16u) + ~"#";
|
||||
let a = {pos: pos, len: len, s: istr::to_estr(s)};
|
||||
let a = {pos: pos, len: len, s: @s};
|
||||
abbrevs.insert(t, a);
|
||||
}
|
||||
ret;
|
||||
|
@ -1232,7 +1232,8 @@ fn make_generic_glue(cx: &@local_ctxt, sp: &span, t: ty::t, llfn: ValueRef,
|
||||
let start = time::get_time();
|
||||
let llval = make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
|
||||
let end = time::get_time();
|
||||
log_fn_time(cx.ccx, "glue " + name + " " + ty_to_short_str(cx.ccx.tcx, t),
|
||||
log_fn_time(cx.ccx, "glue " + name + " " +
|
||||
istr::to_estr(ty_to_short_str(cx.ccx.tcx, t)),
|
||||
start, end);
|
||||
ret llval;
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ type ctxt =
|
||||
freevars: freevars::freevar_map,
|
||||
tcache: type_cache,
|
||||
rcache: creader_cache,
|
||||
short_names_cache: hashmap<t, str>,
|
||||
short_names_cache: hashmap<t, @istr>,
|
||||
has_pointer_cache: hashmap<t, bool>,
|
||||
kind_cache: hashmap<t, ast::kind>,
|
||||
owns_heap_mem_cache: hashmap<t, bool>,
|
||||
|
@ -147,13 +147,13 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
||||
ty_param(id, _) {
|
||||
"'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)])
|
||||
}
|
||||
_ { ty_to_short_str(cx, typ) }
|
||||
_ { istr::to_estr(ty_to_short_str(cx, typ)) }
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_to_short_str(cx: &ctxt, typ: t) -> str {
|
||||
fn ty_to_short_str(cx: &ctxt, typ: t) -> istr {
|
||||
let s = encoder::encoded_ty(cx, typ);
|
||||
if str::byte_len(s) >= 32u { s = str::substr(s, 0u, 32u); }
|
||||
if istr::byte_len(s) >= 32u { s = istr::substr(s, 0u, 32u); }
|
||||
ret s;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user