Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline len and is_empty in collections #56403

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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