Skip to content

Commit

Permalink
Optimize StringWriter scenarios involving SetWriteSizeHint(): res…
Browse files Browse the repository at this point in the history
…ize the

destination to capacity and set up the buffer right at the end of
`SetWriteSizeHintImpl()`, instead of waiting for e.g. `Push()` falling to
`PushSlow()`, synchronizing the buffer, figuring out that the current capacity
will be sufficient, and finally doing the same.

This speeds up some simple usages by about 10%.

PiperOrigin-RevId: 566338632
  • Loading branch information
QrczakMK committed Sep 18, 2023
1 parent dc2854f commit 163de7d
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions riegeli/bytes/string_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void StringWriterBase::SetWriteSizeHintImpl(
std::move(secondary_buffer_).AppendTo(dest);
secondary_buffer_.Clear();
}
GrowDestToCapacityAndMakeBuffer(dest, IntCast<size_t>(start_pos()));
}

bool StringWriterBase::PushSlow(size_t min_length, size_t recommended_length) {
Expand Down

0 comments on commit 163de7d

Please sign in to comment.