mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 13:18:54 +01:00
rustc: Move the interner over to interior vectors
This commit is contained in:
parent
717ac3df77
commit
e066bae56e
@ -378,7 +378,7 @@ fn populate_type_store(&ctxt cx) {
|
||||
intern(cx, ty_task, none[str]);
|
||||
intern(cx, ty_type, none[str]);
|
||||
intern(cx, ty_bot, none[str]);
|
||||
assert (vec::len(cx.ts.vect) == idx_first_others);
|
||||
assert (ivec::len(cx.ts.vect) == idx_first_others);
|
||||
}
|
||||
|
||||
fn mk_rcache() -> creader_cache {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// An "interner" is a data structure that associates values with uint tags and
|
||||
// allows bidirectional lookup; i.e. given a value, one can easily find the
|
||||
// type, and vice versa.
|
||||
import std::vec;
|
||||
import std::ivec;
|
||||
import std::map;
|
||||
import std::map::hashmap;
|
||||
import std::map::hashfn;
|
||||
@ -12,24 +12,24 @@ import std::option::some;
|
||||
|
||||
type interner[T] =
|
||||
rec(hashmap[T, uint] map,
|
||||
mutable vec[T] vect,
|
||||
mutable T[] vect,
|
||||
hashfn[T] hasher,
|
||||
eqfn[T] eqer);
|
||||
|
||||
fn mk[T](hashfn[T] hasher, eqfn[T] eqer) -> interner[T] {
|
||||
auto m = map::mk_hashmap[T, uint](hasher, eqer);
|
||||
let vec[T] vect = [];
|
||||
ret rec(map=m, mutable vect=vect, hasher=hasher, eqer=eqer);
|
||||
ret rec(map=m, mutable vect=~[], hasher=hasher, eqer=eqer);
|
||||
}
|
||||
fn intern[T](&interner[T] itr, &T val) -> uint {
|
||||
alt (itr.map.find(val)) {
|
||||
case (some(?idx)) { ret idx; }
|
||||
case (none) {
|
||||
auto new_idx = vec::len[T](itr.vect);
|
||||
auto new_idx = ivec::len[T](itr.vect);
|
||||
itr.map.insert(val, new_idx);
|
||||
itr.vect += [val];
|
||||
itr.vect += ~[val];
|
||||
ret new_idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
fn get[T](&interner[T] itr, uint idx) -> T { ret itr.vect.(idx); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user