Skip to content

Commit 233319f

Browse files
authored
Rollup merge of #77818 - bugadani:range, r=oli-obk
Mono collector: replace pair of ints with Range I found the initial PR (#33171) that introduced this piece of code but I didn't find any information about why a tuple was preferred over a `Range<usize>`. I'm hoping there are no technical reasons to not do this.
2 parents fe0d5b6 + 0a2a68e commit 233319f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

compiler/rustc_mir/src/monomorphize/collector.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ use rustc_session::config::EntryFnType;
197197
use rustc_span::source_map::{dummy_spanned, respan, Span, Spanned, DUMMY_SP};
198198
use smallvec::SmallVec;
199199
use std::iter;
200+
use std::ops::Range;
200201
use std::path::PathBuf;
201202

202203
#[derive(PartialEq)]
@@ -210,9 +211,8 @@ pub enum MonoItemCollectionMode {
210211
pub struct InliningMap<'tcx> {
211212
// Maps a source mono item to the range of mono items
212213
// accessed by it.
213-
// The two numbers in the tuple are the start (inclusive) and
214-
// end index (exclusive) within the `targets` vecs.
215-
index: FxHashMap<MonoItem<'tcx>, (usize, usize)>,
214+
// The range selects elements within the `targets` vecs.
215+
index: FxHashMap<MonoItem<'tcx>, Range<usize>>,
216216
targets: Vec<MonoItem<'tcx>>,
217217

218218
// Contains one bit per mono item in the `targets` field. That bit
@@ -245,7 +245,7 @@ impl<'tcx> InliningMap<'tcx> {
245245
}
246246

247247
let end_index = self.targets.len();
248-
assert!(self.index.insert(source, (start_index, end_index)).is_none());
248+
assert!(self.index.insert(source, start_index..end_index).is_none());
249249
}
250250

251251
// Internally iterate over all items referenced by `source` which will be
@@ -254,9 +254,9 @@ impl<'tcx> InliningMap<'tcx> {
254254
where
255255
F: FnMut(MonoItem<'tcx>),
256256
{
257-
if let Some(&(start_index, end_index)) = self.index.get(&source) {
258-
for (i, candidate) in self.targets[start_index..end_index].iter().enumerate() {
259-
if self.inlines.contains(start_index + i) {
257+
if let Some(range) = self.index.get(&source) {
258+
for (i, candidate) in self.targets[range.clone()].iter().enumerate() {
259+
if self.inlines.contains(range.start + i) {
260260
f(*candidate);
261261
}
262262
}
@@ -268,8 +268,8 @@ impl<'tcx> InliningMap<'tcx> {
268268
where
269269
F: FnMut(MonoItem<'tcx>, &[MonoItem<'tcx>]),
270270
{
271-
for (&accessor, &(start_index, end_index)) in &self.index {
272-
f(accessor, &self.targets[start_index..end_index])
271+
for (&accessor, range) in &self.index {
272+
f(accessor, &self.targets[range.clone()])
273273
}
274274
}
275275
}

0 commit comments

Comments
 (0)