librustc: Optimize metadata::decoder::item_name.
This commit is contained in:
parent
53f54dda60
commit
4c29b4cb93
4 changed files with 48 additions and 2 deletions
|
@ -18,9 +18,11 @@ use util::interner;
|
|||
|
||||
use core::cast;
|
||||
use core::char;
|
||||
use core::cmp::Equiv;
|
||||
use core::hashmap::HashSet;
|
||||
use core::str;
|
||||
use core::task;
|
||||
use core::to_bytes;
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
|
@ -355,6 +357,19 @@ pub mod special_idents {
|
|||
pub static type_self: ident = ident { repr: 36u, ctxt: 0}; // `Self`
|
||||
}
|
||||
|
||||
pub struct StringRef<'self>(&'self str);
|
||||
|
||||
impl<'self> Equiv<@~str> for StringRef<'self> {
|
||||
#[inline(always)]
|
||||
fn equiv(&self, other: &@~str) -> bool { str::eq_slice(**self, **other) }
|
||||
}
|
||||
|
||||
impl<'self> to_bytes::IterBytes for StringRef<'self> {
|
||||
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
|
||||
(**self).iter_bytes(lsb0, f);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ident_interner {
|
||||
priv interner: Interner<@~str>,
|
||||
}
|
||||
|
@ -372,6 +387,13 @@ pub impl ident_interner {
|
|||
fn len(&self) -> uint {
|
||||
self.interner.len()
|
||||
}
|
||||
fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q)
|
||||
-> Option<ast::ident> {
|
||||
match self.interner.find_equiv(val) {
|
||||
Some(v) => Some(ast::ident { repr: v }),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_ident_interner() -> @ident_interner {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue