Description
size_hint()
can sometimes allow for more efficient memory allocations, and other good performance things.
I intend to make a PR to implement the trivial / easy ones, at least. I've already made a PR for the first batch, #49201. The ones in that PR are omitted from this list.
This list will be updated as I sort through for false-positives.
Liballoc:
Range<'a, K, V>
(Add size_hints for btree iterators #49550)This is hard, but doable, and useful.RangeMut<'a, K, V>
(Add size_hints for btree iterators #49550)This is hard, but doable, and useful.MergeIter<K, V, I>
(Add size_hints for btree iterators #49550)This is hard, but doable, and useful.Range<'a, T>
(Add size_hints for btree iterators #49550)This is hard, but doable, and useful.
Libcore:
Impossible to provide upper or lower bounds.Pattern: $forward_iterator<'a, P>
Impossible to provide upper or lower bounds.Pattern: $reverse_iterator<'a, P>
Libfmt_macros:
Both impossible and irrelevant.Parser<'a>
Libproc_macro:
Implementation is not trivial. It would be nice to do it eventually, though.TokenTreeIter
Librustc:
Not trivial, and probably going to change.Ancestors
No way to define an upper bound.Elaborator<'cx, 'gcx, 'tcx>
No way to define an upper bound.SupertraitDefIds<'cx, 'gcx, 'tcx>
No way to define an upper bound.TypeWalker<'tcx>
Librustdoc:
Libstd:
- fs
- io
- net
Depreciated.Lines<B>
There's no way to provide anything better thanIncoming<'a>
(1, None)
- path
Writing aComponents<'a>
size_hint
for this is hard. But it would be useful; this is oftencollect()
-ed.Writing aAncestors<'a>
size_hint
for this is hard, and not very useful.
- sync
Inherently unbounded iterator.Iter<'a, T>
Inherently unbounded iterator.TryIter<'a, T>
Inherently unbounded iterator.IntoIter<T>
Impossible to write an upper bound.Packets
- sys
- sys_common
There's no safe way to do this.LookupHost
- unicode
Libsyntax:
Cargo:
rust-lang/cargo#5211
I found them by running grep -r -n "impl.*\bIterator for \|fn size_hint" src > size_hint_todo.txt
. Then, delete any pairs of an Iterator
line followed by a size_hint
line, and manually check the remaining Iterator
lines for false positives.
It may be a good idea to make a lint for implementing size_hint. It would be opt-in, of course. It's really easy to forget, even if you're trying to optimize performance.
Activity
Add size_hints for btree iterators
Implement size_hint on various sys iterators
Implement size_hint for several unicode-based iterators.
KodrAus commentedon Aug 22, 2020
It looks like this one has been idle for a few years with PRs closed (mostly just from inactivity). In an effort to prune our open tracking issues to those with unstable features and those that are in progress I’ll go ahead and close this one, but if anybody from @rust-lang/libs thinks we should keep it open please feel free to re-open!
2 remaining items