Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3255)

Unified Diff: blimp/net/compressed_packet_writer.cc

Issue 1882043003: Blimp: add padding for zlib framing to buffer preallocation calculations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}
« blimp/net/compressed_packet_unittest.cc ('K') | « blimp/net/compressed_packet_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698