Remove syntax and syntax_pos thread locals

This commit is contained in:
John Kåre Alsaker 2018-03-07 02:44:10 +01:00
parent fab632f975
commit cbdf4ec03e
29 changed files with 1212 additions and 998 deletions

View file

@ -30,15 +30,10 @@ use ptr::P;
use symbol::Symbol;
use tokenstream::{TokenStream, TokenTree, Delimited};
use util::ThinVec;
use GLOBALS;
use std::cell::RefCell;
use std::iter;
thread_local! {
static USED_ATTRS: RefCell<Vec<u64>> = RefCell::new(Vec::new());
static KNOWN_ATTRS: RefCell<Vec<u64>> = RefCell::new(Vec::new());
}
enum AttrError {
MultipleItem(Name),
UnknownMetaItem(Name),
@ -65,22 +60,24 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) {
pub fn mark_used(attr: &Attribute) {
debug!("Marking {:?} as used.", attr);
let AttrId(id) = attr.id;
USED_ATTRS.with(|slot| {
GLOBALS.with(|globals| {
let mut slot = globals.used_attrs.lock();
let idx = (id / 64) as usize;
let shift = id % 64;
if slot.borrow().len() <= idx {
slot.borrow_mut().resize(idx + 1, 0);
if slot.len() <= idx {
slot.resize(idx + 1, 0);
}
slot.borrow_mut()[idx] |= 1 << shift;
slot[idx] |= 1 << shift;
});
}
pub fn is_used(attr: &Attribute) -> bool {
let AttrId(id) = attr.id;
USED_ATTRS.with(|slot| {
GLOBALS.with(|globals| {
let slot = globals.used_attrs.lock();
let idx = (id / 64) as usize;
let shift = id % 64;
slot.borrow().get(idx).map(|bits| bits & (1 << shift) != 0)
slot.get(idx).map(|bits| bits & (1 << shift) != 0)
.unwrap_or(false)
})
}
@ -88,22 +85,24 @@ pub fn is_used(attr: &Attribute) -> bool {
pub fn mark_known(attr: &Attribute) {
debug!("Marking {:?} as known.", attr);
let AttrId(id) = attr.id;
KNOWN_ATTRS.with(|slot| {
GLOBALS.with(|globals| {
let mut slot = globals.known_attrs.lock();
let idx = (id / 64) as usize;
let shift = id % 64;
if slot.borrow().len() <= idx {
slot.borrow_mut().resize(idx + 1, 0);
if slot.len() <= idx {
slot.resize(idx + 1, 0);
}
slot.borrow_mut()[idx] |= 1 << shift;
slot[idx] |= 1 << shift;
});
}
pub fn is_known(attr: &Attribute) -> bool {
let AttrId(id) = attr.id;
KNOWN_ATTRS.with(|slot| {
GLOBALS.with(|globals| {
let slot = globals.known_attrs.lock();
let idx = (id / 64) as usize;
let shift = id % 64;
slot.borrow().get(idx).map(|bits| bits & (1 << shift) != 0)
slot.get(idx).map(|bits| bits & (1 << shift) != 0)
.unwrap_or(false)
})
}