Skip to content

Commit

Permalink
Avoid exp increase when cap is enough
Browse files Browse the repository at this point in the history
In `BufReadIter::read_exact_to_vec` we can skip safe capacity
doubling magic if capacity is already enough to store the result.
  • Loading branch information
stepancheg committed May 20, 2019
1 parent 97274ef commit 3fa92bb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion protobuf/src/buf_read_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<'ignore> BufReadIter<'ignore> {

target.clear();

if count >= READ_RAW_BYTES_MAX_ALLOC {
if count >= READ_RAW_BYTES_MAX_ALLOC && count > target.capacity() {
// avoid calling `reserve` on buf with very large buffer: could be a malformed message

target.reserve(READ_RAW_BYTES_MAX_ALLOC);
Expand Down

0 comments on commit 3fa92bb

Please sign in to comment.