From 96315ab194016300a663e61c8ba797d0416c23aa Mon Sep 17 00:00:00 2001 From: Michael Cahill Date: Tue, 24 Feb 2015 15:19:20 +1100 Subject: SERVER-17299 Eliminate memory allocation from snappy_compress. (cherry picked from commit c614b21cc563dbb400f7258124fc5d2ed58b4dce) --- src/third_party/snappy-1.1.2/snappy-internal.h | 2 +- src/third_party/snappy-1.1.2/snappy.cc | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/third_party/snappy-1.1.2/snappy-internal.h b/src/third_party/snappy-1.1.2/snappy-internal.h index c99d33130b1..dd6888bd96b 100644 --- a/src/third_party/snappy-1.1.2/snappy-internal.h +++ b/src/third_party/snappy-1.1.2/snappy-internal.h @@ -47,7 +47,7 @@ class WorkingMemory { uint16* GetHashTable(size_t input_size, int* table_size); private: - uint16 small_table_[1<<10]; // 2KB + uint16 small_table_[1<<14]; // 32KB uint16* large_table_; // Allocated only when needed DISALLOW_COPY_AND_ASSIGN(WorkingMemory); diff --git a/src/third_party/snappy-1.1.2/snappy.cc b/src/third_party/snappy-1.1.2/snappy.cc index 8414d2581fe..776a045cce9 100644 --- a/src/third_party/snappy-1.1.2/snappy.cc +++ b/src/third_party/snappy-1.1.2/snappy.cc @@ -940,16 +940,16 @@ size_t Compress(Source* reader, Sink* writer) { // Compress input_fragment and append to dest const int max_output = MaxCompressedLength(num_to_read); - // Need a scratch buffer for the output, in case the byte sink doesn't - // have room for us directly. - if (scratch_output == NULL) { - scratch_output = new char[max_output]; - } else { - // Since we encode kBlockSize regions followed by a region - // which is <= kBlockSize in length, a previously allocated - // scratch_output[] region is big enough for this iteration. - } + // If the byte sink doesn't have room for us directly, allocate a scratch + // buffer. + // + // Since we encode kBlockSize regions followed by a region + // which is <= kBlockSize in length, a previously allocated + // scratch_output[] region is big enough for this iteration. char* dest = writer->GetAppendBuffer(max_output, scratch_output); + if (dest == NULL) { + dest = scratch_output = new char[max_output]; + } char* end = internal::CompressFragment(fragment, fragment_size, dest, table, table_size); writer->Append(dest, end - dest); -- cgit v1.2.1