Skip to content

Commit 2e46ac6

Browse files
committed
librustc: De-@mut the short names cache
1 parent 2612d76 commit 2e46ac6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/librustc/metadata/tyencode.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,27 @@ fn mywrite(w: @mut MemWriter, fmt: &fmt::Arguments) {
6060
pub fn enc_ty(w: @mut MemWriter, cx: @ctxt, t: ty::t) {
6161
match cx.abbrevs {
6262
ac_no_abbrevs => {
63-
let result_str = match cx.tcx.short_names_cache.find(&t) {
64-
Some(&s) => s,
63+
let result_str_opt;
64+
{
65+
let short_names_cache = cx.tcx.short_names_cache.borrow();
66+
result_str_opt = short_names_cache.get()
67+
.find(&t)
68+
.map(|result| *result);
69+
}
70+
let result_str = match result_str_opt {
71+
Some(s) => s,
6572
None => {
6673
let wr = @mut MemWriter::new();
6774
enc_sty(wr, cx, &ty::get(t).sty);
6875
let s = str::from_utf8(*wr.inner_ref()).to_managed();
69-
cx.tcx.short_names_cache.insert(t, s);
76+
let mut short_names_cache = cx.tcx
77+
.short_names_cache
78+
.borrow_mut();
79+
short_names_cache.get().insert(t, s);
7080
s
71-
}
72-
};
73-
w.write(result_str.as_bytes());
81+
}
82+
};
83+
w.write(result_str.as_bytes());
7484
}
7585
ac_use_abbrevs(abbrevs) => {
7686
match abbrevs.find(&t) {

src/librustc/middle/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ struct ctxt_ {
307307
freevars: freevars::freevar_map,
308308
tcache: type_cache,
309309
rcache: creader_cache,
310-
short_names_cache: @mut HashMap<t, @str>,
310+
short_names_cache: RefCell<HashMap<t, @str>>,
311311
needs_unwind_cleanup_cache: @mut HashMap<t, bool>,
312312
tc_cache: @mut HashMap<uint, TypeContents>,
313313
ast_ty_to_ty_cache: @mut HashMap<NodeId, ast_ty_to_ty_cache_entry>,
@@ -993,7 +993,7 @@ pub fn mk_ctxt(s: session::Session,
993993
freevars: freevars,
994994
tcache: @mut HashMap::new(),
995995
rcache: mk_rcache(),
996-
short_names_cache: new_ty_hash(),
996+
short_names_cache: RefCell::new(HashMap::new()),
997997
needs_unwind_cleanup_cache: new_ty_hash(),
998998
tc_cache: @mut HashMap::new(),
999999
ast_ty_to_ty_cache: @mut HashMap::new(),

0 commit comments

Comments
 (0)