Skip to content

Commit d94dc8d

Browse files
authored
Rollup merge of rust-lang#90787 - JohnTitor:inline-sorted-index-map, r=oli-obk
Add `#[inline]`s to `SortedIndexMultiMap` They're small enough and good candidates to add `#[inline]` generally.
2 parents 9200527 + 8d4fbc9 commit d94dc8d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

compiler/rustc_data_structures/src/sorted_map/index_map.rs

+10
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,47 @@ pub struct SortedIndexMultiMap<I: Idx, K, V> {
3434
}
3535

3636
impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
37+
#[inline]
3738
pub fn new() -> Self {
3839
SortedIndexMultiMap { items: IndexVec::new(), idx_sorted_by_item_key: Vec::new() }
3940
}
4041

42+
#[inline]
4143
pub fn len(&self) -> usize {
4244
self.items.len()
4345
}
4446

47+
#[inline]
4548
pub fn is_empty(&self) -> bool {
4649
self.items.is_empty()
4750
}
4851

4952
/// Returns an iterator over the items in the map in insertion order.
53+
#[inline]
5054
pub fn into_iter(self) -> impl DoubleEndedIterator<Item = (K, V)> {
5155
self.items.into_iter()
5256
}
5357

5458
/// Returns an iterator over the items in the map in insertion order along with their indices.
59+
#[inline]
5560
pub fn into_iter_enumerated(self) -> impl DoubleEndedIterator<Item = (I, (K, V))> {
5661
self.items.into_iter_enumerated()
5762
}
5863

5964
/// Returns an iterator over the items in the map in insertion order.
65+
#[inline]
6066
pub fn iter(&self) -> impl '_ + DoubleEndedIterator<Item = (&K, &V)> {
6167
self.items.iter().map(|(ref k, ref v)| (k, v))
6268
}
6369

6470
/// Returns an iterator over the items in the map in insertion order along with their indices.
71+
#[inline]
6572
pub fn iter_enumerated(&self) -> impl '_ + DoubleEndedIterator<Item = (I, (&K, &V))> {
6673
self.items.iter_enumerated().map(|(i, (ref k, ref v))| (i, (k, v)))
6774
}
6875

6976
/// Returns the item in the map with the given index.
77+
#[inline]
7078
pub fn get(&self, idx: I) -> Option<&(K, V)> {
7179
self.items.get(idx)
7280
}
@@ -75,6 +83,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
7583
///
7684
/// If there are multiple items that are equivalent to `key`, they will be yielded in
7785
/// insertion order.
86+
#[inline]
7887
pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator<Item = &'a V> {
7988
self.get_by_key_enumerated(key).map(|(_, v)| v)
8089
}
@@ -84,6 +93,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
8493
///
8594
/// If there are multiple items that are equivalent to `key`, they will be yielded in
8695
/// insertion order.
96+
#[inline]
8797
pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator<Item = (I, &V)> {
8898
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
8999
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {

0 commit comments

Comments
 (0)