about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStein Somers <git@steinsomers.be>2020-09-27 01:10:30 +0200
committerStein Somers <git@steinsomers.be>2020-10-03 21:18:18 +0200
commit3b051d0171b4e15aff4d2ecacf7659f7278e8e09 (patch)
tree96042624a60f12b4a2ace5ba6cdeedd11ac01895
parent90c8b43bc3cb867715bd08d93c3bb6e06819c3b1 (diff)
downloadrust-3b051d0171b4e15aff4d2ecacf7659f7278e8e09.tar.gz
rust-3b051d0171b4e15aff4d2ecacf7659f7278e8e09.zip
BTreeMap: comment why drain_filter's size_hint is somewhat pessimistictid
-rw-r--r--library/alloc/src/collections/btree/map.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs
index ee0f525fb15..4ca93a4eb83 100644
--- a/library/alloc/src/collections/btree/map.rs
+++ b/library/alloc/src/collections/btree/map.rs
@@ -1748,6 +1748,10 @@ impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> {
 
     /// Implementation of a typical `DrainFilter::size_hint` method.
     pub(super) fn size_hint(&self) -> (usize, Option<usize>) {
+        // In most of the btree iterators, `self.length` is the number of elements
+        // yet to be visited. Here, it includes elements that were visited and that
+        // the predicate decided not to drain. Making this upper bound more accurate
+        // requires maintaining an extra field and is not worth while.
         (0, Some(*self.length))
     }
 }