diff options
| author | bors <bors@rust-lang.org> | 2014-05-08 01:26:39 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-08 01:26:39 -0700 |
| commit | b9ff86e27f53af10de0302033b659061d659b69b (patch) | |
| tree | 92749609d3a8645b7ad37a47fd20c8e60df77299 /src/libsyntax | |
| parent | c39b1cb1bed78d989b1011f54f6febb7e9e46d94 (diff) | |
| parent | ab92ea526d455b402efbccc7160c8aec0237c88f (diff) | |
| download | rust-b9ff86e27f53af10de0302033b659061d659b69b.tar.gz rust-b9ff86e27f53af10de0302033b659061d659b69b.zip | |
auto merge of #13835 : alexcrichton/rust/localdata, r=brson
This commit brings the local_data api up to modern rust standards with a few key improvements: * All functionality is now exposed as a method on the keys themselves. Instead of importing std::local_data, you now use "key.set()" and "key.get()". * All closures have been removed in favor of RAII functionality. This means that get() and get_mut() no long require closures, but rather return Option<SmartPointer> where the smart pointer takes care of relinquishing the borrow and also implements the necessary Deref traits * The modify() function was removed to cut the local_data interface down to its bare essentials (similarly to how RefCell removed set/get). [breaking-change]
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/mtwt.rs | 39 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 7 |
2 files changed, 19 insertions, 27 deletions
diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index 4ae9d436972..6ac3becf0b6 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -18,7 +18,6 @@ use ast::{Ident, Mrk, Name, SyntaxContext}; use std::cell::RefCell; -use std::local_data; use std::rc::Rc; use collections::HashMap; @@ -91,17 +90,14 @@ fn new_rename_internal(id: Ident, pub fn with_sctable<T>(op: |&SCTable| -> T) -> T { local_data_key!(sctable_key: Rc<SCTable>) - local_data::get(sctable_key, |opt_ts| { - let table = match opt_ts { - None => { - let ts = Rc::new(new_sctable_internal()); - local_data::set(sctable_key, ts.clone()); - ts - } - Some(ts) => ts.clone() - }; - op(&*table) - }) + match sctable_key.get() { + Some(ts) => op(&**ts), + None => { + let ts = Rc::new(new_sctable_internal()); + sctable_key.replace(Some(ts.clone())); + op(&*ts) + } + } } // Make a fresh syntax context table with EmptyCtxt in slot zero @@ -154,17 +150,14 @@ type ResolveTable = HashMap<(Name,SyntaxContext),Name>; fn with_resolve_table_mut<T>(op: |&mut ResolveTable| -> T) -> T { local_data_key!(resolve_table_key: Rc<RefCell<ResolveTable>>) - local_data::get(resolve_table_key, |opt_ts| { - let table = match opt_ts { - None => { - let ts = Rc::new(RefCell::new(HashMap::new())); - local_data::set(resolve_table_key, ts.clone()); - ts - } - Some(ts) => ts.clone() - }; - op(&mut *table.borrow_mut()) - }) + match resolve_table_key.get() { + Some(ts) => op(&mut *ts.borrow_mut()), + None => { + let ts = Rc::new(RefCell::new(HashMap::new())); + resolve_table_key.replace(Some(ts.clone())); + op(&mut *ts.borrow_mut()) + } + } } // Resolve a syntax object to a name, per MTWT. diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index e4e71baad44..131e744d83d 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -19,7 +19,6 @@ use util::interner; use serialize::{Decodable, Decoder, Encodable, Encoder}; use std::cast; use std::fmt; -use std::local_data; use std::path::BytesContainer; use std::rc::Rc; use std::strbuf::StrBuf; @@ -529,11 +528,11 @@ pub type IdentInterner = StrInterner; // FIXME(eddyb) #8726 This should probably use a task-local reference. pub fn get_ident_interner() -> Rc<IdentInterner> { local_data_key!(key: Rc<::parse::token::IdentInterner>) - match local_data::get(key, |k| k.map(|k| k.clone())) { - Some(interner) => interner, + match key.get() { + Some(interner) => interner.clone(), None => { let interner = Rc::new(mk_fresh_ident_interner()); - local_data::set(key, interner.clone()); + key.replace(Some(interner.clone())); interner } } |
