Skip to content

Commit 7317bf8

Browse files
committed
pre-intern some fixed names so they can be used as constants
1 parent 9a7890d commit 7317bf8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/libsyntax/parse/token.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,18 @@ pure fn is_bar(t: token) -> bool {
279279

280280
type ident_interner = util::interner::interner<@~str>;
281281

282+
mod special_idents {
283+
const underscore : uint = 0u;
284+
const anon : uint = 1u;
285+
const destr : uint = 2u; // 'drop', but that's reserved
286+
}
287+
282288
fn mk_ident_interner() -> ident_interner {
283-
let rv = @interner::mk::<@~str>(|x| str::hash(*x),
284-
|x,y| str::eq(*x, *y));
289+
/* the indices here must correspond to the numbers in special_idents */
290+
let init_vec = ~[@~"_", @~"anon", @~"drop"];
291+
292+
let rv = @interner::mk_prefill::<@~str>(|x| str::hash(*x),
293+
|x,y| str::eq(*x, *y), init_vec);
285294
rv
286295
}
287296

src/libsyntax/util/interner.rs

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ fn mk<T: const copy>(+hasher: hashfn<T>, +eqer: eqfn<T>) -> interner<T> {
1818
return hi as interner::<T>;
1919
}
2020

21+
fn mk_prefill<T: const copy>(hasher: hashfn<T>, eqer: eqfn<T>,
22+
init: ~[T]) -> interner<T> {
23+
24+
let rv = mk(hasher, eqer);
25+
for init.each() |v| { rv.intern(v); }
26+
return rv;
27+
}
28+
29+
2130
/* when traits can extend traits, we should extend index<uint,T> to get [] */
2231
trait interner<T: const copy> {
2332
fn intern(T) -> uint;

0 commit comments

Comments
 (0)