Skip to content

Commit ad17c3d

Browse files
Rollup merge of rust-lang#110182 - WaffleLapkin:neither, r=Nilstrieb
Use `itertools::Either` instead of own impl Yeah.
2 parents 8019a1d + a329592 commit ad17c3d

File tree

5 files changed

+37
-109
lines changed

5 files changed

+37
-109
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4575,6 +4575,7 @@ dependencies = [
45754575
"elsa",
45764576
"ena",
45774577
"indexmap",
4578+
"itertools",
45784579
"jobserver",
45794580
"libc",
45804581
"measureme",

compiler/rustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tempfile = "3.2"
3333
thin-vec = "0.2.12"
3434
tracing = "0.1"
3535
elsa = "=1.7.1"
36+
itertools = "0.10.1"
3637

3738
[dependencies.parking_lot]
3839
version = "0.11"

compiler/rustc_data_structures/src/sso/either_iter.rs

-73
This file was deleted.

compiler/rustc_data_structures/src/sso/map.rs

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
use super::either_iter::EitherIter;
21
use crate::fx::FxHashMap;
32
use arrayvec::ArrayVec;
3+
use itertools::Either;
44
use std::fmt;
55
use std::hash::Hash;
66
use std::ops::Index;
77

8-
// For pointer-sized arguments arrays
9-
// are faster than set/map for up to 64
10-
// arguments.
11-
//
12-
// On the other hand such a big array
13-
// hurts cache performance, makes passing
14-
// sso structures around very expensive.
15-
//
16-
// Biggest performance benefit is gained
17-
// for reasonably small arrays that stay
18-
// small in vast majority of cases.
19-
//
20-
// '8' is chosen as a sane default, to be
21-
// reevaluated later.
8+
/// For pointer-sized arguments arrays
9+
/// are faster than set/map for up to 64
10+
/// arguments.
11+
///
12+
/// On the other hand such a big array
13+
/// hurts cache performance, makes passing
14+
/// sso structures around very expensive.
15+
///
16+
/// Biggest performance benefit is gained
17+
/// for reasonably small arrays that stay
18+
/// small in vast majority of cases.
19+
///
20+
/// '8' is chosen as a sane default, to be
21+
/// reevaluated later.
2222
const SSO_ARRAY_SIZE: usize = 8;
2323

2424
/// Small-storage-optimized implementation of a map.
@@ -138,35 +138,35 @@ impl<K, V> SsoHashMap<K, V> {
138138
/// The iterator element type is `&'a K`.
139139
pub fn keys(&self) -> impl Iterator<Item = &'_ K> {
140140
match self {
141-
SsoHashMap::Array(array) => EitherIter::Left(array.iter().map(|(k, _v)| k)),
142-
SsoHashMap::Map(map) => EitherIter::Right(map.keys()),
141+
SsoHashMap::Array(array) => Either::Left(array.iter().map(|(k, _v)| k)),
142+
SsoHashMap::Map(map) => Either::Right(map.keys()),
143143
}
144144
}
145145

146146
/// An iterator visiting all values in arbitrary order.
147147
/// The iterator element type is `&'a V`.
148148
pub fn values(&self) -> impl Iterator<Item = &'_ V> {
149149
match self {
150-
SsoHashMap::Array(array) => EitherIter::Left(array.iter().map(|(_k, v)| v)),
151-
SsoHashMap::Map(map) => EitherIter::Right(map.values()),
150+
SsoHashMap::Array(array) => Either::Left(array.iter().map(|(_k, v)| v)),
151+
SsoHashMap::Map(map) => Either::Right(map.values()),
152152
}
153153
}
154154

155155
/// An iterator visiting all values mutably in arbitrary order.
156156
/// The iterator element type is `&'a mut V`.
157157
pub fn values_mut(&mut self) -> impl Iterator<Item = &'_ mut V> {
158158
match self {
159-
SsoHashMap::Array(array) => EitherIter::Left(array.iter_mut().map(|(_k, v)| v)),
160-
SsoHashMap::Map(map) => EitherIter::Right(map.values_mut()),
159+
SsoHashMap::Array(array) => Either::Left(array.iter_mut().map(|(_k, v)| v)),
160+
SsoHashMap::Map(map) => Either::Right(map.values_mut()),
161161
}
162162
}
163163

164164
/// Clears the map, returning all key-value pairs as an iterator. Keeps the
165165
/// allocated memory for reuse.
166166
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_ {
167167
match self {
168-
SsoHashMap::Array(array) => EitherIter::Left(array.drain(..)),
169-
SsoHashMap::Map(map) => EitherIter::Right(map.drain()),
168+
SsoHashMap::Array(array) => Either::Left(array.drain(..)),
169+
SsoHashMap::Map(map) => Either::Right(map.drain()),
170170
}
171171
}
172172
}
@@ -406,16 +406,16 @@ where
406406
}
407407

408408
impl<K, V> IntoIterator for SsoHashMap<K, V> {
409-
type IntoIter = EitherIter<
410-
<ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
409+
type IntoIter = Either<
410+
<ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
411411
<FxHashMap<K, V> as IntoIterator>::IntoIter,
412412
>;
413413
type Item = <Self::IntoIter as Iterator>::Item;
414414

415415
fn into_iter(self) -> Self::IntoIter {
416416
match self {
417-
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter()),
418-
SsoHashMap::Map(map) => EitherIter::Right(map.into_iter()),
417+
SsoHashMap::Array(array) => Either::Left(array.into_iter()),
418+
SsoHashMap::Map(map) => Either::Right(map.into_iter()),
419419
}
420420
}
421421
}
@@ -435,9 +435,9 @@ fn adapt_array_mut_it<K, V>(pair: &mut (K, V)) -> (&K, &mut V) {
435435
}
436436

437437
impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {
438-
type IntoIter = EitherIter<
438+
type IntoIter = Either<
439439
std::iter::Map<
440-
<&'a ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
440+
<&'a ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
441441
fn(&'a (K, V)) -> (&'a K, &'a V),
442442
>,
443443
<&'a FxHashMap<K, V> as IntoIterator>::IntoIter,
@@ -446,16 +446,16 @@ impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {
446446

447447
fn into_iter(self) -> Self::IntoIter {
448448
match self {
449-
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_ref_it)),
450-
SsoHashMap::Map(map) => EitherIter::Right(map.iter()),
449+
SsoHashMap::Array(array) => Either::Left(array.into_iter().map(adapt_array_ref_it)),
450+
SsoHashMap::Map(map) => Either::Right(map.iter()),
451451
}
452452
}
453453
}
454454

455455
impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {
456-
type IntoIter = EitherIter<
456+
type IntoIter = Either<
457457
std::iter::Map<
458-
<&'a mut ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
458+
<&'a mut ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
459459
fn(&'a mut (K, V)) -> (&'a K, &'a mut V),
460460
>,
461461
<&'a mut FxHashMap<K, V> as IntoIterator>::IntoIter,
@@ -464,8 +464,8 @@ impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {
464464

465465
fn into_iter(self) -> Self::IntoIter {
466466
match self {
467-
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_mut_it)),
468-
SsoHashMap::Map(map) => EitherIter::Right(map.iter_mut()),
467+
SsoHashMap::Array(array) => Either::Left(array.into_iter().map(adapt_array_mut_it)),
468+
SsoHashMap::Map(map) => Either::Right(map.iter_mut()),
469469
}
470470
}
471471
}

compiler/rustc_data_structures/src/sso/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod either_iter;
21
mod map;
32
mod set;
43

0 commit comments

Comments
 (0)