Chromium Code Reviews| Index: blimp/net/compressed_packet_writer.cc |
| diff --git a/blimp/net/compressed_packet_writer.cc b/blimp/net/compressed_packet_writer.cc |
| index 3fe885611fb04092d01fe361e4362c56b81543a6..1eae0bfba759b9b0896ad173b174715e01008051 100644 |
| --- a/blimp/net/compressed_packet_writer.cc |
| +++ b/blimp/net/compressed_packet_writer.cc |
| @@ -20,6 +20,10 @@ namespace { |
| // compression. (See zconf.h for details on memLevel semantics.) |
| const int kZlibMemoryLevel = 9; |
| +// Byte count of the zlib end-of-block marker (0x00, 0x00, 0xFF, 0xFF). |
| +// Used for buffer preallocation. |
| +const size_t kZlibBlockFooterLength = 4; |
|
Wez
2016/04/12 23:54:34
nit: You call it a marker but name it "footer" - b
Kevin M
2016/04/13 00:53:34
Done, done.
|
| + |
| } // namespace |
| CompressedPacketWriter::CompressedPacketWriter( |
| @@ -88,8 +92,11 @@ int CompressedPacketWriter::Compress( |
| const scoped_refptr<net::GrowableIOBuffer>& dest_buf) { |
| DCHECK_EQ(0, dest_buf->offset()); |
| + // Preallocate a buffer that's large enough to fit the compressed contents of |
| + // src_buf, plus some overhead for zlib. |
| const int zlib_output_ubound = |
| - deflateBound(&zlib_stream_, src_buf->BytesRemaining()); |
| + deflateBound(&zlib_stream_, src_buf->BytesRemaining()) + |
| + kZlibBlockFooterLength; |
|
Wez
2016/04/12 23:54:34
Indentation looks wrong - git cl format this?
Kevin M
2016/04/13 00:53:35
Already formatted.
|
| if (dest_buf->capacity() < zlib_output_ubound) { |
| dest_buf->SetCapacity(zlib_output_ubound); |
| } |