Skip to content

Commit fce06e3

Browse files
committed
compiler: use vector instead of hashmap in rustc_abi's TargetDataLayout
1 parent 1374d68 commit fce06e3

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ use std::ops::{Add, AddAssign, Deref, Mul, RangeInclusive, Sub};
4747
use std::str::FromStr;
4848

4949
use bitflags::bitflags;
50-
use rustc_data_structures::fx::FxHashMap;
5150
#[cfg(feature = "nightly")]
5251
use rustc_data_structures::stable_hasher::StableOrd;
5352
use rustc_hashes::Hash64;
@@ -254,7 +253,7 @@ pub struct TargetDataLayout {
254253
pub vector_align: Vec<(Size, AbiAlign)>,
255254

256255
pub default_address_space: AddressSpace,
257-
pub address_space_info: FxHashMap<AddressSpace, AddressSpaceInfo>,
256+
pub address_space_info: Vec<(AddressSpace, AddressSpaceInfo)>,
258257

259258
pub instruction_address_space: AddressSpace,
260259

@@ -286,14 +285,14 @@ impl Default for TargetDataLayout {
286285
(Size::from_bits(128), AbiAlign::new(align(128))),
287286
],
288287
default_address_space: AddressSpace::ZERO,
289-
address_space_info: FxHashMap::from_iter([(
288+
address_space_info: vec![(
290289
AddressSpace::ZERO,
291290
AddressSpaceInfo {
292291
pointer_size: Size::from_bits(64),
293292
pointer_align: AbiAlign::new(align(64)),
294293
pointer_index: Size::from_bits(64),
295294
},
296-
)]),
295+
)],
297296
instruction_address_space: AddressSpace::ZERO,
298297
c_enum_min_size: Integer::I32,
299298
}
@@ -388,11 +387,10 @@ impl TargetDataLayout {
388387
pointer_size,
389388
pointer_align: parse_align(a, p)?,
390389
};
391-
392-
dl.address_space_info
393-
.entry(addr_space)
394-
.and_modify(|v| *v = info)
395-
.or_insert(info);
390+
match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
391+
Some(e) => e.1 = info,
392+
None => dl.address_space_info.push((addr_space, info)),
393+
}
396394
}
397395
[p, s, _pr, i, a @ ..] if p.starts_with("p") => {
398396
let p = p.strip_prefix(char::is_alphabetic).unwrap_or_default();
@@ -409,10 +407,10 @@ impl TargetDataLayout {
409407
pointer_index: parse_size(i, p)?,
410408
};
411409

412-
dl.address_space_info
413-
.entry(addr_space)
414-
.and_modify(|v| *v = info)
415-
.or_insert(info);
410+
match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
411+
Some(e) => e.1 = info,
412+
None => dl.address_space_info.push((addr_space, info)),
413+
}
416414
}
417415

418416
[s, a @ ..] if s.starts_with('i') => {
@@ -450,7 +448,7 @@ impl TargetDataLayout {
450448
}
451449
}
452450

453-
if !dl.address_space_info.contains_key(&default_address_space) {
451+
if dl.address_space_info.iter().find(|(a, _)| *a == default_address_space).is_none() {
454452
return Err(TargetDataLayoutErrors::MissingAddressSpaceInfo {
455453
addr_space: default_address_space,
456454
});
@@ -459,11 +457,17 @@ impl TargetDataLayout {
459457
// Inherit, if not given, address space informations for specific LLVM elements from the
460458
// default data address space.
461459

462-
if !dl.address_space_info.contains_key(&dl.instruction_address_space) {
463-
dl.address_space_info.insert(
460+
if dl.address_space_info.iter().find(|(a, _)| *a == dl.instruction_address_space).is_none()
461+
{
462+
dl.address_space_info.push((
464463
dl.instruction_address_space,
465-
dl.address_space_info.get(&default_address_space).unwrap().clone(),
466-
);
464+
dl.address_space_info
465+
.iter()
466+
.find(|(a, _)| *a == default_address_space)
467+
.unwrap()
468+
.1
469+
.clone(),
470+
));
467471
}
468472

469473
Ok(dl)
@@ -545,8 +549,8 @@ impl TargetDataLayout {
545549
/// Get the pointer size in a specific address space.
546550
#[inline]
547551
pub fn pointer_size_in(&self, c: AddressSpace) -> Size {
548-
if let Some(c) = self.address_space_info.get(&c) {
549-
c.pointer_size
552+
if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
553+
e.1.pointer_size
550554
} else {
551555
panic!("Use of unknown address space {c:?}");
552556
}
@@ -561,8 +565,8 @@ impl TargetDataLayout {
561565
/// Get the pointer index in a specific address space.
562566
#[inline]
563567
pub fn pointer_index_in(&self, c: AddressSpace) -> Size {
564-
if let Some(c) = self.address_space_info.get(&c) {
565-
c.pointer_index
568+
if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
569+
e.1.pointer_index
566570
} else {
567571
panic!("Use of unknown address space {c:?}");
568572
}
@@ -577,8 +581,8 @@ impl TargetDataLayout {
577581
/// Get the pointer alignment in a specific address space.
578582
#[inline]
579583
pub fn pointer_align_in(&self, c: AddressSpace) -> AbiAlign {
580-
if let Some(c) = self.address_space_info.get(&c) {
581-
c.pointer_align
584+
if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
585+
e.1.pointer_align
582586
} else {
583587
panic!("Use of unknown address space {c:?}");
584588
}

0 commit comments

Comments
 (0)