diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-12-27 16:20:10 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-01-03 14:01:59 -0800 |
| commit | 96f807def6abb5da33618712dbdd4a8cc7cb81cf (patch) | |
| tree | dbc384eb80fad9cd41d059c41cf31a1b6d393a2d /src/libsyntax/util | |
| parent | 9d6f8cdefad70fe670147a4dc10a72e53c4e261a (diff) | |
| download | rust-96f807def6abb5da33618712dbdd4a8cc7cb81cf.tar.gz rust-96f807def6abb5da33618712dbdd4a8cc7cb81cf.zip | |
libsyntax: De-`@mut` the interner map
Diffstat (limited to 'src/libsyntax/util')
| -rw-r--r-- | src/libsyntax/util/interner.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index c144b36a86f..413a40959c5 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -14,11 +14,12 @@ use ast::Name; +use std::cell::RefCell; use std::cmp::Equiv; use std::hashmap::HashMap; pub struct Interner<T> { - priv map: @mut HashMap<T, Name>, + priv map: @RefCell<HashMap<T, Name>>, priv vect: @mut ~[T], } @@ -26,7 +27,7 @@ pub struct Interner<T> { impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> { pub fn new() -> Interner<T> { Interner { - map: @mut HashMap::new(), + map: @RefCell::new(HashMap::new()), vect: @mut ~[], } } @@ -40,14 +41,15 @@ impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> { } pub fn intern(&self, val: T) -> Name { - match self.map.find(&val) { + let mut map = self.map.borrow_mut(); + match map.get().find(&val) { Some(&idx) => return idx, None => (), } let vect = &mut *self.vect; let new_idx = vect.len() as Name; - self.map.insert(val.clone(), new_idx); + map.get().insert(val.clone(), new_idx); vect.push(val); new_idx } @@ -70,7 +72,8 @@ impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> { pub fn find_equiv<Q:Hash + IterBytes + Equiv<T>>(&self, val: &Q) -> Option<Name> { - match self.map.find_equiv(val) { + let map = self.map.borrow(); + match map.get().find_equiv(val) { Some(v) => Some(*v), None => None, } @@ -80,7 +83,7 @@ impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> { // A StrInterner differs from Interner<String> in that it accepts // borrowed pointers rather than @ ones, resulting in less allocation. pub struct StrInterner { - priv map: @mut HashMap<@str, Name>, + priv map: @RefCell<HashMap<@str, Name>>, priv vect: @mut ~[@str], } @@ -88,7 +91,7 @@ pub struct StrInterner { impl StrInterner { pub fn new() -> StrInterner { StrInterner { - map: @mut HashMap::new(), + map: @RefCell::new(HashMap::new()), vect: @mut ~[], } } @@ -100,14 +103,15 @@ impl StrInterner { } pub fn intern(&self, val: &str) -> Name { - match self.map.find_equiv(&val) { + let mut map = self.map.borrow_mut(); + match map.get().find_equiv(&val) { Some(&idx) => return idx, None => (), } let new_idx = self.len() as Name; let val = val.to_managed(); - self.map.insert(val, new_idx); + map.get().insert(val, new_idx); self.vect.push(val); new_idx } @@ -142,7 +146,8 @@ impl StrInterner { pub fn find_equiv<Q:Hash + IterBytes + Equiv<@str>>(&self, val: &Q) -> Option<Name> { - match self.map.find_equiv(val) { + let map = self.map.borrow(); + match map.get().find_equiv(val) { Some(v) => Some(*v), None => None, } |
