diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-01-08 10:35:15 -0800 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-02 01:44:47 +1100 |
| commit | 70c5a0fbf784d6a89b1c2c50f9fe83093bd21abc (patch) | |
| tree | c0d73d05918545051a9e1d10f5496ee588df3693 /src/libsyntax/util/interner.rs | |
| parent | 1d494198bbb9701b6336febcf9d0ceb39e4b7975 (diff) | |
| download | rust-70c5a0fbf784d6a89b1c2c50f9fe83093bd21abc.tar.gz rust-70c5a0fbf784d6a89b1c2c50f9fe83093bd21abc.zip | |
libsyntax: Introduce an `InternedString` type to reduce `@str` in the
compiler and use it for attributes
Diffstat (limited to 'src/libsyntax/util/interner.rs')
| -rw-r--r-- | src/libsyntax/util/interner.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index fdc54f1f140..c0fe19ede01 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -14,6 +14,7 @@ use ast::Name; +use std::cast; use std::cell::RefCell; use std::cmp::Equiv; use std::hashmap::HashMap; @@ -151,6 +152,16 @@ impl StrInterner { vect.get()[idx] } + /// Returns this string with lifetime tied to the interner. Since + /// strings may never be removed from the interner, this is safe. + pub fn get_ref<'a>(&'a self, idx: Name) -> &'a str { + let vect = self.vect.borrow(); + let s: &str = vect.get()[idx]; + unsafe { + cast::transmute(s) + } + } + pub fn len(&self) -> uint { let vect = self.vect.borrow(); vect.get().len() |
