Skip to content

Commit 6b725d2

Browse files
committed
Directly cache the SpanData.
1 parent a62a464 commit 6b725d2

File tree

1 file changed

+5
-2
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+5
-2
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
99
use rustc_hir::ItemId;
1010
use rustc_query_system::ich::StableHashingContext;
1111
use rustc_session::config::OptLevel;
12-
use rustc_span::source_map::Span;
1312
use rustc_span::symbol::Symbol;
13+
use rustc_span::{Span, SpanData};
1414
use std::fmt;
1515
use std::hash::Hash;
1616

@@ -348,8 +348,10 @@ impl<'tcx> CodegenUnit<'tcx> {
348348
) -> Vec<(MonoItem<'tcx>, (Linkage, Visibility))> {
349349
// The codegen tests rely on items being process in the same order as
350350
// they appear in the file, so for local items, we sort by span first
351+
//
352+
// We directly cache a SpanData to avoid having to query the interner for each comparison.
351353
#[derive(PartialEq, Eq, PartialOrd, Ord)]
352-
pub struct ItemSortKey<'tcx>(Option<Span>, SymbolName<'tcx>);
354+
pub struct ItemSortKey<'tcx>(Option<SpanData>, SymbolName<'tcx>);
353355

354356
fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> {
355357
let span = match item {
@@ -373,6 +375,7 @@ impl<'tcx> CodegenUnit<'tcx> {
373375
MonoItem::Static(def_id) => tcx.hir().span_if_local(def_id),
374376
MonoItem::GlobalAsm(item_id) => Some(tcx.def_span(item_id.def_id)),
375377
};
378+
let span = span.map(Span::data);
376379
ItemSortKey(span, item.symbol_name(tcx))
377380
}
378381

0 commit comments

Comments
 (0)