Take does not reserve its limit on read_to_end #51746
Labels
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Using
readable.take(x).read_to_end(&mut buf)
can cause the capacity ofbuf
to exceed what is needed.I tried this code:
https://play.rust-lang.org/?gist=83401a704fddcec007bcfb0ecc85fc6d&version=nightly&mode=debug
I expected to see this happen:
readable.take(1)
should reserve1
.Take
should reserve a maximum oftake.limit()
.Instead, this happened:
buf
capacity increased becausereadable.take(1)
reserved32
which exceeds itslimit
.Take
will always reserve in increments of32
rather than its knownlimit
.I'm new to Rust; my guess is implementing
read_to_end
specifically forTake
is the way to improve this.The text was updated successfully, but these errors were encountered: