ast: Compress AttrId
from usize
to u32
Also stop encoding/decoding it entirely
This commit is contained in:
parent
5f13820478
commit
13dd9aff64
@ -31,7 +31,6 @@ use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
|
|||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::thin_vec::ThinVec;
|
use rustc_data_structures::thin_vec::ThinVec;
|
||||||
use rustc_index::vec::Idx;
|
|
||||||
use rustc_macros::HashStable_Generic;
|
use rustc_macros::HashStable_Generic;
|
||||||
use rustc_serialize::{self, Decoder, Encoder};
|
use rustc_serialize::{self, Decoder, Encoder};
|
||||||
use rustc_span::source_map::{respan, Spanned};
|
use rustc_span::source_map::{respan, Spanned};
|
||||||
@ -2251,27 +2250,22 @@ pub enum AttrStyle {
|
|||||||
Inner,
|
Inner,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, Copy)]
|
rustc_index::newtype_index! {
|
||||||
pub struct AttrId(pub usize);
|
pub struct AttrId {
|
||||||
|
ENCODABLE = custom
|
||||||
impl Idx for AttrId {
|
DEBUG_FORMAT = "AttrId({})"
|
||||||
fn new(idx: usize) -> Self {
|
|
||||||
AttrId(idx)
|
|
||||||
}
|
|
||||||
fn index(self) -> usize {
|
|
||||||
self.0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl rustc_serialize::Encodable for AttrId {
|
impl rustc_serialize::Encodable for AttrId {
|
||||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
fn encode<S: Encoder>(&self, _: &mut S) -> Result<(), S::Error> {
|
||||||
s.emit_unit()
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl rustc_serialize::Decodable for AttrId {
|
impl rustc_serialize::Decodable for AttrId {
|
||||||
fn decode<D: Decoder>(d: &mut D) -> Result<AttrId, D::Error> {
|
fn decode<D: Decoder>(_: &mut D) -> Result<AttrId, D::Error> {
|
||||||
d.read_nil().map(|_| crate::attr::mk_attr_id())
|
Ok(crate::attr::mk_attr_id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,14 +366,14 @@ pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
crate fn mk_attr_id() -> AttrId {
|
crate fn mk_attr_id() -> AttrId {
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicU32;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
static NEXT_ATTR_ID: AtomicUsize = AtomicUsize::new(0);
|
static NEXT_ATTR_ID: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
let id = NEXT_ATTR_ID.fetch_add(1, Ordering::SeqCst);
|
let id = NEXT_ATTR_ID.fetch_add(1, Ordering::SeqCst);
|
||||||
assert!(id != ::std::usize::MAX);
|
assert!(id != u32::MAX);
|
||||||
AttrId(id)
|
AttrId::from_u32(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_attr(style: AttrStyle, path: Path, args: MacArgs, span: Span) -> Attribute {
|
pub fn mk_attr(style: AttrStyle, path: Path, args: MacArgs, span: Span) -> Attribute {
|
||||||
|
Loading…
Reference in New Issue
Block a user