|
3 | 3 |
|
4 | 4 | use crate::ty; |
5 | 5 | use crate::ty::subst::{GenericArg, GenericArgKind}; |
6 | | -use arrayvec::ArrayVec; |
7 | | -use rustc_data_structures::fx::FxHashSet; |
| 6 | +use rustc_data_structures::mini_set::MiniSet; |
8 | 7 | use smallvec::{self, SmallVec}; |
9 | | -use std::hash::Hash; |
10 | | - |
11 | | -/// Small-storage-optimized implementation of a set |
12 | | -/// made specifically for walking type tree. |
13 | | -/// |
14 | | -/// Stores elements in a small array up to a certain length |
15 | | -/// and switches to `HashSet` when that length is exceeded. |
16 | | -pub enum MiniSet<T> { |
17 | | - Array(ArrayVec<[T; 8]>), |
18 | | - Set(FxHashSet<T>), |
19 | | -} |
20 | | - |
21 | | -impl<T: Eq + Hash + Copy> MiniSet<T> { |
22 | | - /// Creates an empty `MiniSet`. |
23 | | - pub fn new() -> Self { |
24 | | - MiniSet::Array(ArrayVec::new()) |
25 | | - } |
26 | | - |
27 | | - /// Adds a value to the set. |
28 | | - /// |
29 | | - /// If the set did not have this value present, true is returned. |
30 | | - /// |
31 | | - /// If the set did have this value present, false is returned. |
32 | | - pub fn insert(&mut self, elem: T) -> bool { |
33 | | - match self { |
34 | | - MiniSet::Array(array) => { |
35 | | - if array.iter().any(|e| *e == elem) { |
36 | | - false |
37 | | - } else { |
38 | | - if array.try_push(elem).is_err() { |
39 | | - let mut set: FxHashSet<T> = array.iter().copied().collect(); |
40 | | - set.insert(elem); |
41 | | - *self = MiniSet::Set(set); |
42 | | - } |
43 | | - true |
44 | | - } |
45 | | - } |
46 | | - MiniSet::Set(set) => set.insert(elem), |
47 | | - } |
48 | | - } |
49 | | -} |
50 | 8 |
|
51 | 9 | // The TypeWalker's stack is hot enough that it's worth going to some effort to |
52 | 10 | // avoid heap allocations. |
|
0 commit comments