summary refs log tree commit diff
path: root/src/libsyntax/util
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-06-13 03:02:55 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-06-13 10:20:52 +1000
commit096f6f56a8178bd7f4b69a2ea909838e782766fb (patch)
tree37513f0d39fdfb4d5a702a72abd7423c93c51cdf /src/libsyntax/util
parent641910dc1340b7786fd758282bac88639a58ddcd (diff)
downloadrust-096f6f56a8178bd7f4b69a2ea909838e782766fb.tar.gz
rust-096f6f56a8178bd7f4b69a2ea909838e782766fb.zip
Use @str instead of @~str in libsyntax and librustc. Fixes #5048.
This almost removes the StringRef wrapper, since all strings are
Equiv-alent now. Removes a lot of `/* bad */ copy *`'s, and converts
several things to be &'static str (the lint table and the intrinsics
table).

There are many instances of .to_managed(), unfortunately.
Diffstat (limited to 'src/libsyntax/util')
-rw-r--r--src/libsyntax/util/interner.rs60
-rw-r--r--src/libsyntax/util/parser_testing.rs22
2 files changed, 41 insertions, 41 deletions
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs
index b55050184fe..d4f183ada7b 100644
--- a/src/libsyntax/util/interner.rs
+++ b/src/libsyntax/util/interner.rs
@@ -19,7 +19,6 @@ use core::prelude::*;
 
 use core::cmp::Equiv;
 use core::hashmap::HashMap;
-use syntax::parse::token::StringRef;
 
 pub struct Interner<T> {
     priv map: @mut HashMap<T, uint>,
@@ -80,8 +79,8 @@ impl<T:Eq + IterBytes + Hash + Const + Copy> 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, uint>,
-    priv vect: @mut ~[@~str],
+    priv map: @mut HashMap<@str, uint>,
+    priv vect: @mut ~[@str],
 }
 
 // when traits can extend traits, we should extend index<uint,T> to get []
@@ -95,37 +94,38 @@ impl StrInterner {
 
     pub fn prefill(init: &[&str]) -> StrInterner {
         let rv = StrInterner::new();
-        for init.each() |v| { rv.intern(*v); }
+        for init.each |&v| { rv.intern(v); }
         rv
     }
 
     pub fn intern(&self, val: &str) -> uint {
-        match self.map.find_equiv(&StringRef(val)) {
+        match self.map.find_equiv(&val) {
             Some(&idx) => return idx,
             None => (),
         }
 
         let new_idx = self.len();
-        self.map.insert(@val.to_owned(), new_idx);
-        self.vect.push(@val.to_owned());
+        let val = val.to_managed();
+        self.map.insert(val, new_idx);
+        self.vect.push(val);
         new_idx
     }
 
     pub fn gensym(&self, val: &str) -> uint {
         let new_idx = self.len();
         // leave out of .map to avoid colliding
-        self.vect.push(@val.to_owned());
+        self.vect.push(val.to_managed());
         new_idx
     }
 
     // this isn't "pure" in the traditional sense, because it can go from
     // failing to returning a value as items are interned. But for typestate,
     // where we first check a pred and then rely on it, ceasing to fail is ok.
-    pub fn get(&self, idx: uint) -> @~str { self.vect[idx] }
+    pub fn get(&self, idx: uint) -> @str { self.vect[idx] }
 
     pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() }
 
-    pub fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q)
+    pub fn find_equiv<Q:Hash + IterBytes + Equiv<@str>>(&self, val: &Q)
                                                          -> Option<uint> {
         match self.map.find_equiv(val) {
             Some(v) => Some(*v),
@@ -140,41 +140,41 @@ mod tests {
     #[test]
     #[should_fail]
     fn i1 () {
-        let i : Interner<@~str> = Interner::new();
+        let i : Interner<@str> = Interner::new();
         i.get(13);
     }
 
     #[test]
     fn i2 () {
-        let i : Interner<@~str> = Interner::new();
+        let i : Interner<@str> = Interner::new();
         // first one is zero:
-        assert_eq!(i.intern (@~"dog"), 0);
+        assert_eq!(i.intern (@"dog"), 0);
         // re-use gets the same entry:
-        assert_eq!(i.intern (@~"dog"), 0);
+        assert_eq!(i.intern (@"dog"), 0);
         // different string gets a different #:
-        assert_eq!(i.intern (@~"cat"), 1);
-        assert_eq!(i.intern (@~"cat"), 1);
+        assert_eq!(i.intern (@"cat"), 1);
+        assert_eq!(i.intern (@"cat"), 1);
         // dog is still at zero
-        assert_eq!(i.intern (@~"dog"), 0);
+        assert_eq!(i.intern (@"dog"), 0);
         // gensym gets 3
-        assert_eq!(i.gensym (@~"zebra" ), 2);
+        assert_eq!(i.gensym (@"zebra" ), 2);
         // gensym of same string gets new number :
-        assert_eq!(i.gensym (@~"zebra" ), 3);
+        assert_eq!(i.gensym (@"zebra" ), 3);
         // gensym of *existing* string gets new number:
-        assert_eq!(i.gensym (@~"dog"), 4);
-        assert_eq!(i.get(0), @~"dog");
-        assert_eq!(i.get(1), @~"cat");
-        assert_eq!(i.get(2), @~"zebra");
-        assert_eq!(i.get(3), @~"zebra");
-        assert_eq!(i.get(4), @~"dog");
+        assert_eq!(i.gensym (@"dog"), 4);
+        assert_eq!(i.get(0), @"dog");
+        assert_eq!(i.get(1), @"cat");
+        assert_eq!(i.get(2), @"zebra");
+        assert_eq!(i.get(3), @"zebra");
+        assert_eq!(i.get(4), @"dog");
     }
 
     #[test]
     fn i3 () {
-        let i : Interner<@~str> = Interner::prefill([@~"Alan",@~"Bob",@~"Carol"]);
-        assert_eq!(i.get(0), @~"Alan");
-        assert_eq!(i.get(1), @~"Bob");
-        assert_eq!(i.get(2), @~"Carol");
-        assert_eq!(i.intern(@~"Bob"), 1);
+        let i : Interner<@str> = Interner::prefill([@"Alan",@"Bob",@"Carol"]);
+        assert_eq!(i.get(0), @"Alan");
+        assert_eq!(i.get(1), @"Bob");
+        assert_eq!(i.get(2), @"Carol");
+        assert_eq!(i.intern(@"Bob"), 1);
     }
 }
diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs
index 76055ca7914..d0961ddbc70 100644
--- a/src/libsyntax/util/parser_testing.rs
+++ b/src/libsyntax/util/parser_testing.rs
@@ -18,50 +18,50 @@ use parse::token;
 
 // map a string to tts, using a made-up filename: return both the token_trees
 // and the ParseSess
-pub fn string_to_tts_and_sess (source_str : @~str) -> (~[ast::token_tree],@mut ParseSess) {
+pub fn string_to_tts_and_sess (source_str : @str) -> (~[ast::token_tree],@mut ParseSess) {
     let ps = new_parse_sess(None);
-    (filemap_to_tts(ps,string_to_filemap(ps,source_str,~"bogofile")),ps)
+    (filemap_to_tts(ps,string_to_filemap(ps,source_str,@"bogofile")),ps)
 }
 
-pub fn string_to_parser_and_sess(source_str: @~str) -> (Parser,@mut ParseSess) {
+pub fn string_to_parser_and_sess(source_str: @str) -> (Parser,@mut ParseSess) {
     let ps = new_parse_sess(None);
-    (new_parser_from_source_str(ps,~[],~"bogofile",source_str),ps)
+    (new_parser_from_source_str(ps,~[],@"bogofile",source_str),ps)
 }
 
 // map string to parser (via tts)
-pub fn string_to_parser(source_str: @~str) -> Parser {
+pub fn string_to_parser(source_str: @str) -> Parser {
     let (p,_) = string_to_parser_and_sess(source_str);
     p
 }
 
-pub fn string_to_crate (source_str : @~str) -> @ast::crate {
+pub fn string_to_crate (source_str : @str) -> @ast::crate {
     string_to_parser(source_str).parse_crate_mod()
 }
 
 // parse a string, return an expr
-pub fn string_to_expr (source_str : @~str) -> @ast::expr {
+pub fn string_to_expr (source_str : @str) -> @ast::expr {
     string_to_parser(source_str).parse_expr()
 }
 
 // parse a string, return an item
-pub fn string_to_item (source_str : @~str) -> Option<@ast::item> {
+pub fn string_to_item (source_str : @str) -> Option<@ast::item> {
     string_to_parser(source_str).parse_item(~[])
 }
 
 // parse a string, return an item and the ParseSess
-pub fn string_to_item_and_sess (source_str : @~str) -> (Option<@ast::item>,@mut ParseSess) {
+pub fn string_to_item_and_sess (source_str : @str) -> (Option<@ast::item>,@mut ParseSess) {
     let (p,ps) = string_to_parser_and_sess(source_str);
     (p.parse_item(~[]),ps)
 }
 
 // parse a string, return a stmt
-pub fn string_to_stmt(source_str : @~str) -> @ast::stmt {
+pub fn string_to_stmt(source_str : @str) -> @ast::stmt {
     string_to_parser(source_str).parse_stmt(~[])
 }
 
 // parse a string, return a pat. Uses "irrefutable"... which doesn't
 // (currently) affect parsing.
-pub fn string_to_pat(source_str : @~str) -> @ast::pat {
+pub fn string_to_pat(source_str : @str) -> @ast::pat {
     string_to_parser(source_str).parse_pat()
 }