Skip to content

Commit 51c5e5f

Browse files
committed
rustc_metadata: use 0 in index::Index to indicate missing entries.
1 parent 78fa21d commit 51c5e5f

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/librustc_metadata/index.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace};
44
use rustc_serialize::opaque::Encoder;
55
use std::marker::PhantomData;
66
use std::num::NonZeroUsize;
7-
use std::u32;
87
use log::debug;
98

109
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
@@ -73,7 +72,7 @@ impl FixedSizeEncoding for u32 {
7372
/// of each DefIndex. It is not required that all definitions appear
7473
/// in the metadata, nor that they are serialized in order, and
7574
/// therefore we first allocate the vector here and fill it with
76-
/// `u32::MAX`. Whenever an index is visited, we fill in the
75+
/// `0`. Whenever an index is visited, we fill in the
7776
/// appropriate spot by calling `record_position`. We should never
7877
/// visit the same index twice.
7978
pub struct Index<'tcx> {
@@ -84,8 +83,8 @@ pub struct Index<'tcx> {
8483
impl Index<'tcx> {
8584
pub fn new((max_index_lo, max_index_hi): (usize, usize)) -> Self {
8685
Index {
87-
positions: [vec![0xff; max_index_lo * 4],
88-
vec![0xff; max_index_hi * 4]],
86+
positions: [vec![0; max_index_lo * 4],
87+
vec![0; max_index_hi * 4]],
8988
_marker: PhantomData,
9089
}
9190
}
@@ -96,13 +95,13 @@ impl Index<'tcx> {
9695
}
9796

9897
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'tcx>>) {
99-
assert!(entry.position.get() < (u32::MAX as usize));
10098
let position = entry.position.get() as u32;
99+
assert_eq!(position as usize, entry.position.get());
101100
let space_index = item.address_space().index();
102101
let array_index = item.as_array_index();
103102

104103
let positions = &mut self.positions[space_index];
105-
assert!(u32::read_from_bytes_at(positions, array_index) == u32::MAX,
104+
assert!(u32::read_from_bytes_at(positions, array_index) == 0,
106105
"recorded position for item {:?} twice, first at {:?} and now at {:?}",
107106
item,
108107
u32::read_from_bytes_at(positions, array_index),
@@ -147,12 +146,7 @@ impl Lazy<[Index<'tcx>]> {
147146
};
148147

149148
let position = u32::read_from_bytes_at(bytes, 1 + i);
150-
if position == u32::MAX {
151-
debug!("Index::lookup: position=u32::MAX");
152-
None
153-
} else {
154-
debug!("Index::lookup: position={:?}", position);
155-
Some(Lazy::from_position(NonZeroUsize::new(position as usize).unwrap()))
156-
}
149+
debug!("Index::lookup: position={:?}", position);
150+
NonZeroUsize::new(position as usize).map(Lazy::from_position)
157151
}
158152
}

0 commit comments

Comments
 (0)