Skip to content

Commit bfa68b9

Browse files
committed
Auto merge of #56403 - ljedrz:inline_len_and_is_empty, r=<try>
Inline len and is_empty in collections Is there any reason not to? All of these are trivial and heavily utilized.
2 parents d311571 + 98c62b8 commit bfa68b9

File tree

8 files changed

+12
-0
lines changed

8 files changed

+12
-0
lines changed

src/liballoc/collections/binary_heap.rs

+2
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ impl<T: Ord> BinaryHeap<T> {
721721
///
722722
/// assert_eq!(heap.len(), 2);
723723
/// ```
724+
#[inline]
724725
#[stable(feature = "rust1", since = "1.0.0")]
725726
pub fn len(&self) -> usize {
726727
self.data.len()
@@ -744,6 +745,7 @@ impl<T: Ord> BinaryHeap<T> {
744745
///
745746
/// assert!(!heap.is_empty());
746747
/// ```
748+
#[inline]
747749
#[stable(feature = "rust1", since = "1.0.0")]
748750
pub fn is_empty(&self) -> bool {
749751
self.len() == 0

src/liballoc/collections/btree/map.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,7 @@ impl<K, V> BTreeMap<K, V> {
20742074
/// a.insert(1, "a");
20752075
/// assert_eq!(a.len(), 1);
20762076
/// ```
2077+
#[inline]
20772078
#[stable(feature = "rust1", since = "1.0.0")]
20782079
pub fn len(&self) -> usize {
20792080
self.length
@@ -2093,6 +2094,7 @@ impl<K, V> BTreeMap<K, V> {
20932094
/// a.insert(1, "a");
20942095
/// assert!(!a.is_empty());
20952096
/// ```
2097+
#[inline]
20962098
#[stable(feature = "rust1", since = "1.0.0")]
20972099
pub fn is_empty(&self) -> bool {
20982100
self.len() == 0

src/liballoc/collections/btree/set.rs

+2
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ impl<T> BTreeSet<T> {
729729
/// v.insert(1);
730730
/// assert_eq!(v.len(), 1);
731731
/// ```
732+
#[inline]
732733
#[stable(feature = "rust1", since = "1.0.0")]
733734
pub fn len(&self) -> usize {
734735
self.map.len()
@@ -746,6 +747,7 @@ impl<T> BTreeSet<T> {
746747
/// v.insert(1);
747748
/// assert!(!v.is_empty());
748749
/// ```
750+
#[inline]
749751
#[stable(feature = "rust1", since = "1.0.0")]
750752
pub fn is_empty(&self) -> bool {
751753
self.len() == 0

src/liballoc/collections/vec_deque.rs

+1
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ impl<T> VecDeque<T> {
932932
/// v.push_front(1);
933933
/// assert!(!v.is_empty());
934934
/// ```
935+
#[inline]
935936
#[stable(feature = "rust1", since = "1.0.0")]
936937
pub fn is_empty(&self) -> bool {
937938
self.tail == self.head

src/liballoc/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,7 @@ impl<T> Vec<T> {
11801180
/// v.push(1);
11811181
/// assert!(!v.is_empty());
11821182
/// ```
1183+
#[inline]
11831184
#[stable(feature = "rust1", since = "1.0.0")]
11841185
pub fn is_empty(&self) -> bool {
11851186
self.len() == 0

src/libstd/collections/hash/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ impl<K, V, S> HashMap<K, V, S>
12151215
/// a.insert(1, "a");
12161216
/// assert_eq!(a.len(), 1);
12171217
/// ```
1218+
#[inline]
12181219
#[stable(feature = "rust1", since = "1.0.0")]
12191220
pub fn len(&self) -> usize {
12201221
self.table.size()

src/libstd/collections/hash/set.rs

+2
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ impl<T, S> HashSet<T, S>
461461
/// v.insert(1);
462462
/// assert_eq!(v.len(), 1);
463463
/// ```
464+
#[inline]
464465
#[stable(feature = "rust1", since = "1.0.0")]
465466
pub fn len(&self) -> usize {
466467
self.map.len()
@@ -478,6 +479,7 @@ impl<T, S> HashSet<T, S>
478479
/// v.insert(1);
479480
/// assert!(!v.is_empty());
480481
/// ```
482+
#[inline]
481483
#[stable(feature = "rust1", since = "1.0.0")]
482484
pub fn is_empty(&self) -> bool {
483485
self.map.is_empty()

src/libstd/collections/hash/table.rs

+1
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ impl<K, V> RawTable<K, V> {
776776

777777
/// The number of elements ever `put` in the hashtable, minus the number
778778
/// of elements ever `take`n.
779+
#[inline]
779780
pub fn size(&self) -> usize {
780781
self.size
781782
}

0 commit comments

Comments
 (0)