mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Avoid as_str()
in ParamTy::is_self
.
It's a hot function, and a direct `Symbol` comparison is faster. The patch also converts some `&InternedString`s to `InternedString`.
This commit is contained in:
parent
6afcb56285
commit
b96be5b188
@ -609,9 +609,9 @@ impl Generics {
|
||||
own_counts
|
||||
}
|
||||
|
||||
pub fn get_named(&self, name: &InternedString) -> Option<&GenericParam> {
|
||||
pub fn get_named(&self, name: InternedString) -> Option<&GenericParam> {
|
||||
for param in &self.params {
|
||||
if *name == param.name.ident().as_interned_str() {
|
||||
if name == param.name.ident().as_interned_str() {
|
||||
return Some(param);
|
||||
}
|
||||
}
|
||||
|
@ -194,20 +194,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
|
||||
if let Some(param) = self.hir()
|
||||
.get_generics(scope)
|
||||
.and_then(|generics| generics.get_named(&br.name))
|
||||
.and_then(|generics| generics.get_named(br.name))
|
||||
{
|
||||
sp = param.span;
|
||||
}
|
||||
(format!("the lifetime {} as defined on", br.name), sp)
|
||||
}
|
||||
ty::ReFree(ty::FreeRegion {
|
||||
bound_region: ty::BoundRegion::BrNamed(_, ref name),
|
||||
bound_region: ty::BoundRegion::BrNamed(_, name),
|
||||
..
|
||||
}) => {
|
||||
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
|
||||
if let Some(param) = self.hir()
|
||||
.get_generics(scope)
|
||||
.and_then(|generics| generics.get_named(&name))
|
||||
.and_then(|generics| generics.get_named(name))
|
||||
{
|
||||
sp = param.span;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||
) -> Option<AnonymousArgInfo<'_>> {
|
||||
let (id, bound_region) = match *anon_region {
|
||||
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
||||
ty::ReEarlyBound(ref ebr) => (
|
||||
ty::ReEarlyBound(ebr) => (
|
||||
self.tcx().parent(ebr.def_id).unwrap(),
|
||||
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
|
||||
),
|
||||
|
@ -1136,7 +1136,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
|
||||
// FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere,
|
||||
// but this should only be possible when using `-Z continue-parse-after-error` like
|
||||
// `compile-fail/issue-36638.rs`.
|
||||
self.name == keywords::SelfUpper.name().as_str() && self.index == 0
|
||||
self.name.as_symbol() == keywords::SelfUpper.name() && self.index == 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,8 @@ impl RegionName {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
crate fn name(&self) -> &InternedString {
|
||||
&self.name
|
||||
crate fn name(&self) -> InternedString {
|
||||
self.name
|
||||
}
|
||||
|
||||
crate fn highlight_region_name(
|
||||
@ -206,7 +206,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
match error_region {
|
||||
ty::ReEarlyBound(ebr) => {
|
||||
if ebr.has_name() {
|
||||
let span = self.get_named_span(tcx, error_region, &ebr.name);
|
||||
let span = self.get_named_span(tcx, error_region, ebr.name);
|
||||
Some(RegionName {
|
||||
name: ebr.name,
|
||||
source: RegionNameSource::NamedEarlyBoundRegion(span)
|
||||
@ -223,7 +223,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
|
||||
ty::ReFree(free_region) => match free_region.bound_region {
|
||||
ty::BoundRegion::BrNamed(_, name) => {
|
||||
let span = self.get_named_span(tcx, error_region, &name);
|
||||
let span = self.get_named_span(tcx, error_region, name);
|
||||
Some(RegionName {
|
||||
name,
|
||||
source: RegionNameSource::NamedFreeRegion(span),
|
||||
@ -306,7 +306,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
&self,
|
||||
tcx: TyCtxt<'_, '_, 'tcx>,
|
||||
error_region: &RegionKind,
|
||||
name: &InternedString,
|
||||
name: InternedString,
|
||||
) -> Span {
|
||||
let scope = error_region.free_region_binding_scope(tcx);
|
||||
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
|
||||
|
Loading…
Reference in New Issue
Block a user