Skip to content

Commit

Permalink
Auto merge of #56403 - ljedrz:inline_len_and_is_empty, r=<try>
Browse files Browse the repository at this point in the history
Inline len and is_empty in collections

Is there any reason not to? All of these are trivial and heavily utilized.
  • Loading branch information
bors committed Dec 1, 2018
2 parents d311571 + 98c62b8 commit bfa68b9
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ impl<T: Ord> BinaryHeap<T> {
///
/// assert_eq!(heap.len(), 2);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.data.len()
Expand All @@ -744,6 +745,7 @@ impl<T: Ord> BinaryHeap<T> {
///
/// assert!(!heap.is_empty());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(1, "a");
/// assert_eq!(a.len(), 1);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.length
Expand All @@ -2093,6 +2094,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(1, "a");
/// assert!(!a.is_empty());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ impl<T> BTreeSet<T> {
/// v.insert(1);
/// assert_eq!(v.len(), 1);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.map.len()
Expand All @@ -746,6 +747,7 @@ impl<T> BTreeSet<T> {
/// v.insert(1);
/// assert!(!v.is_empty());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ impl<T> VecDeque<T> {
/// v.push_front(1);
/// assert!(!v.is_empty());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.tail == self.head
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ impl<T> Vec<T> {
/// v.push(1);
/// assert!(!v.is_empty());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down
1 change: 1 addition & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ impl<K, V, S> HashMap<K, V, S>
/// a.insert(1, "a");
/// assert_eq!(a.len(), 1);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.table.size()
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ impl<T, S> HashSet<T, S>
/// v.insert(1);
/// assert_eq!(v.len(), 1);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.map.len()
Expand All @@ -478,6 +479,7 @@ impl<T, S> HashSet<T, S>
/// v.insert(1);
/// assert!(!v.is_empty());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.map.is_empty()
Expand Down
1 change: 1 addition & 0 deletions src/libstd/collections/hash/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ impl<K, V> RawTable<K, V> {

/// The number of elements ever `put` in the hashtable, minus the number
/// of elements ever `take`n.
#[inline]
pub fn size(&self) -> usize {
self.size
}
Expand Down

0 comments on commit bfa68b9

Please sign in to comment.