diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-24 22:13:16 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-27 15:54:43 -0700 |
| commit | b2408d57f034c0a448b60bf03254d8f73c0882db (patch) | |
| tree | 91a357adc8eb380341861196f0782be05a1c3824 /src/comp/metadata | |
| parent | fcc031c5b4dc8f64c497b8dd1e066068e862bd72 (diff) | |
| download | rust-b2408d57f034c0a448b60bf03254d8f73c0882db.tar.gz rust-b2408d57f034c0a448b60bf03254d8f73c0882db.zip | |
Convert portions of rustc to istrs. Recover a lot of performance.
Issue #855
Diffstat (limited to 'src/comp/metadata')
| -rw-r--r-- | src/comp/metadata/common.rs | 6 | ||||
| -rw-r--r-- | src/comp/metadata/decoder.rs | 3 | ||||
| -rw-r--r-- | src/comp/metadata/encoder.rs | 90 | ||||
| -rw-r--r-- | src/comp/metadata/tyencode.rs | 12 |
4 files changed, 58 insertions, 53 deletions
diff --git a/src/comp/metadata/common.rs b/src/comp/metadata/common.rs index 9d6a2c745f8..02f434c5c50 100644 --- a/src/comp/metadata/common.rs +++ b/src/comp/metadata/common.rs @@ -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; } diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs index 522aba23b6f..97010e0d521 100644 --- a/src/comp/metadata/decoder.rs +++ b/src/comp/metadata/decoder.rs @@ -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))]; } diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index 12db17936dd..1aa89d9a914 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -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(); } diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs index 399ab85fd30..bdb5db6758d 100644 --- a/src/comp/metadata/tyencode.rs +++ b/src/comp/metadata/tyencode.rs @@ -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; |
