rustc: Cache intermediate results of metadata.Encode.ty_str. Shaves 30% off translation time.
This commit is contained in:
parent
3bec4c8193
commit
17daf1f9bf
@ -82,7 +82,19 @@ mod Encode {
|
||||
|
||||
fn enc_ty(&IO.writer w, &@ctxt cx, &ty.t t) {
|
||||
alt (cx.abbrevs) {
|
||||
case (ac_no_abbrevs) { enc_sty(w, cx, ty.struct(cx.tcx, t)); }
|
||||
case (ac_no_abbrevs) {
|
||||
auto result_str;
|
||||
alt (cx.tcx.short_names_cache.find(t)) {
|
||||
case (some[str](?s)) { result_str = s; }
|
||||
case (none[str]) {
|
||||
auto sw = IO.string_writer();
|
||||
enc_sty(sw.get_writer(), cx, ty.struct(cx.tcx, t));
|
||||
result_str = sw.get_str();
|
||||
cx.tcx.short_names_cache.insert(t, result_str);
|
||||
}
|
||||
}
|
||||
w.write_str(result_str);
|
||||
}
|
||||
case (ac_use_abbrevs(?abbrevs)) {
|
||||
alt (abbrevs.find(t)) {
|
||||
case (some[ty_abbrev](?a)) {
|
||||
|
@ -113,6 +113,7 @@ state type crate_ctxt = rec(session.session sess,
|
||||
std.SHA1.sha1 sha,
|
||||
hashmap[ty.t, str] type_sha1s,
|
||||
hashmap[ty.t, metadata.ty_abbrev] type_abbrevs,
|
||||
hashmap[ty.t, str] type_short_names,
|
||||
ty.ctxt tcx,
|
||||
@upcall.upcalls upcalls);
|
||||
|
||||
@ -192,6 +193,7 @@ fn get_type_sha1(@crate_ctxt ccx, ty.t t) -> str {
|
||||
// NB: do *not* use abbrevs here as we want the symbol names
|
||||
// to be independent of one another in the crate.
|
||||
auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata.ac_no_abbrevs);
|
||||
|
||||
ccx.sha.input_str(metadata.Encode.ty_str(cx, t));
|
||||
hash = Str.substr(ccx.sha.result_str(), 0u, 16u);
|
||||
ccx.type_sha1s.insert(t, hash);
|
||||
@ -7694,6 +7696,7 @@ fn trans_crate(session.session sess, @ast.crate crate, ty.ctxt tcx,
|
||||
auto lltypes = Map.mk_hashmap[ty.t,TypeRef](hasher, eqer);
|
||||
auto sha1s = Map.mk_hashmap[ty.t,str](hasher, eqer);
|
||||
auto abbrevs = Map.mk_hashmap[ty.t,metadata.ty_abbrev](hasher, eqer);
|
||||
auto short_names = Map.mk_hashmap[ty.t,str](hasher, eqer);
|
||||
|
||||
auto ccx = @rec(sess = sess,
|
||||
llmod = llmod,
|
||||
@ -7721,6 +7724,7 @@ fn trans_crate(session.session sess, @ast.crate crate, ty.ctxt tcx,
|
||||
sha = std.SHA1.mk_sha1(),
|
||||
type_sha1s = sha1s,
|
||||
type_abbrevs = abbrevs,
|
||||
type_short_names = short_names,
|
||||
tcx = tcx,
|
||||
upcalls = upcall.declare_upcalls(tn, llmod));
|
||||
auto cx = new_local_ctxt(ccx);
|
||||
|
@ -55,7 +55,8 @@ type mt = rec(t ty, ast.mutability mut);
|
||||
type creader_cache = hashmap[tup(int,uint,uint),ty.t];
|
||||
type ctxt = rec(@type_store ts,
|
||||
session.session sess,
|
||||
creader_cache rcache);
|
||||
creader_cache rcache,
|
||||
hashmap[t,str] short_names_cache);
|
||||
type ty_ctxt = ctxt; // Needed for disambiguation from Unify.ctxt.
|
||||
|
||||
// Convert from method type to function type. Pretty easy; we just drop
|
||||
@ -227,7 +228,9 @@ fn mk_rcache() -> creader_cache {
|
||||
fn mk_ctxt(session.session s) -> ctxt {
|
||||
ret rec(ts = mk_type_store(),
|
||||
sess = s,
|
||||
rcache = mk_rcache());
|
||||
rcache = mk_rcache(),
|
||||
short_names_cache =
|
||||
Map.mk_hashmap[ty.t,str](ty.hash_ty, ty.eq_ty));
|
||||
}
|
||||
// Type constructors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user