Introduce InternedString::intern.
`InternedString::intern(x)` is preferable to `Symbol::intern(x).as_interned_str()`, because the former involves one call to `with_interner` while the latter involves two. The case within InternedString::decode() is particularly hot, and this change reduces the number of `with_interner` calls by up to 13%.
This commit is contained in:
parent
b96be5b188
commit
257eaf523f
13 changed files with 60 additions and 66 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
|
||||
use crate::hir::HirId;
|
||||
use syntax::symbol::{Symbol, InternedString};
|
||||
use syntax::symbol::InternedString;
|
||||
use crate::ty::{Instance, TyCtxt};
|
||||
use crate::util::nodemap::FxHashMap;
|
||||
use rustc_data_structures::base_n;
|
||||
|
|
@ -280,7 +280,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> {
|
|||
cgu_name
|
||||
} else {
|
||||
let cgu_name = &cgu_name.as_str()[..];
|
||||
Symbol::intern(&CodegenUnit::mangle_name(cgu_name)).as_interned_str()
|
||||
InternedString::intern(&CodegenUnit::mangle_name(cgu_name))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -336,6 +336,6 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> {
|
|||
write!(cgu_name, ".{}", special_suffix).unwrap();
|
||||
}
|
||||
|
||||
Symbol::intern(&cgu_name[..]).as_interned_str()
|
||||
InternedString::intern(&cgu_name[..])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ use crate::ty::{self, Ty, TyCtxt, TypeFoldable, Predicate, ToPredicate};
|
|||
use crate::ty::subst::{Subst, InternalSubsts};
|
||||
use std::borrow::Cow;
|
||||
use std::iter::{self};
|
||||
use syntax::ast::{self, Name};
|
||||
use syntax::ast::{self};
|
||||
use syntax::symbol::InternedString;
|
||||
use syntax_pos::Span;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
|
|
@ -539,7 +540,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
// are implemented
|
||||
let unsized_self_ty: Ty<'tcx> = self.mk_ty_param(
|
||||
::std::u32::MAX,
|
||||
Name::intern("RustaceansAreAwesome").as_interned_str(),
|
||||
InternedString::intern("RustaceansAreAwesome"),
|
||||
);
|
||||
|
||||
// `Receiver[Self => U]`
|
||||
|
|
|
|||
|
|
@ -312,17 +312,15 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
|
|||
}
|
||||
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
|
||||
use syntax::symbol::Symbol;
|
||||
|
||||
match t.sty {
|
||||
ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
|
||||
self.types.insert(
|
||||
bound_ty.var.as_u32(),
|
||||
match bound_ty.kind {
|
||||
ty::BoundTyKind::Param(name) => name,
|
||||
ty::BoundTyKind::Anon => Symbol::intern(
|
||||
&format!("^{}", bound_ty.var.as_u32())
|
||||
).as_interned_str(),
|
||||
ty::BoundTyKind::Anon =>
|
||||
InternedString::intern(&format!("^{}", bound_ty.var.as_u32()),
|
||||
),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -334,8 +332,6 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
|
|||
}
|
||||
|
||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
|
||||
use syntax::symbol::Symbol;
|
||||
|
||||
match r {
|
||||
ty::ReLateBound(index, br) if *index == self.binder_index => {
|
||||
match br {
|
||||
|
|
@ -344,9 +340,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
|
|||
}
|
||||
|
||||
ty::BoundRegion::BrAnon(var) => {
|
||||
self.regions.insert(Symbol::intern(
|
||||
&format!("'^{}", var)
|
||||
).as_interned_str());
|
||||
self.regions.insert(InternedString::intern(&format!("'^{}", var)));
|
||||
}
|
||||
|
||||
_ => (),
|
||||
|
|
|
|||
|
|
@ -3405,7 +3405,7 @@ impl_stable_hash_for!(struct self::SymbolName {
|
|||
impl SymbolName {
|
||||
pub fn new(name: &str) -> SymbolName {
|
||||
SymbolName {
|
||||
name: Symbol::intern(name).as_interned_str()
|
||||
name: InternedString::intern(name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,8 @@ use crate::middle::region;
|
|||
use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable};
|
||||
use crate::ty::subst::{Kind, Subst, UnpackedKind};
|
||||
use crate::mir::interpret::ConstValue;
|
||||
use syntax::symbol::{keywords, Symbol};
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use syntax::symbol::InternedString;
|
||||
use syntax::symbol::{keywords, InternedString};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::fmt::{self, Write as _};
|
||||
|
|
@ -1285,10 +1283,10 @@ impl<F: fmt::Write> FmtPrinter<'_, 'gcx, 'tcx, F> {
|
|||
{
|
||||
fn name_by_region_index(index: usize) -> InternedString {
|
||||
match index {
|
||||
0 => Symbol::intern("'r"),
|
||||
1 => Symbol::intern("'s"),
|
||||
i => Symbol::intern(&format!("'t{}", i-2)),
|
||||
}.as_interned_str()
|
||||
0 => InternedString::intern("'r"),
|
||||
1 => InternedString::intern("'s"),
|
||||
i => InternedString::intern(&format!("'t{}", i-2)),
|
||||
}
|
||||
}
|
||||
|
||||
// Replace any anonymous late-bound regions with named
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::ty::{self, Ty, TyCtxt, AdtSizedConstraint};
|
||||
use crate::ty::util::NeedsDrop;
|
||||
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::symbol::InternedString;
|
||||
|
||||
pub(super) trait Value<'tcx>: Sized {
|
||||
fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
|
||||
|
|
@ -28,7 +28,7 @@ impl<'tcx> Value<'tcx> for Ty<'tcx> {
|
|||
|
||||
impl<'tcx> Value<'tcx> for ty::SymbolName {
|
||||
fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
|
||||
ty::SymbolName { name: Symbol::intern("<error>").as_interned_str() }
|
||||
ty::SymbolName { name: InternedString::intern("<error>") }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue