@@ -71,10 +71,6 @@ Data read_file_data_or_exit(const char* name) {
7171 return data;
7272}
7373
74- size_t zlib_estimate_compressed_size (size_t input_size) {
75- return compressBound (input_size);
76- }
77-
7874enum zlib_wrapper {
7975 kWrapperNONE ,
8076 kWrapperZLIB ,
@@ -128,10 +124,6 @@ void zlib_compress(
128124 std::string* output,
129125 bool resize_output = false )
130126{
131- if (resize_output)
132- output->resize (zlib_estimate_compressed_size (input_size));
133- size_t output_size = output->size ();
134-
135127 z_stream stream;
136128 memset (&stream, 0 , sizeof (stream));
137129
@@ -140,6 +132,11 @@ void zlib_compress(
140132 if (result != Z_OK)
141133 error_exit (" deflateInit2 failed" , result);
142134
135+ if (resize_output) {
136+ output->resize (deflateBound (&stream, input_size));
137+ }
138+ size_t output_size = output->size ();
139+
143140 stream.next_out = (Bytef*)string_data (output);
144141 stream.avail_out = (uInt)output_size;
145142 stream.next_in = (z_const Bytef*)input;
@@ -299,19 +296,14 @@ void zlib_file(const char* name,
299296
300297 // Pre-grow the output buffer so we don't measure string resize time.
301298 for (int b = 0 ; b < blocks; ++b)
302- compressed[b]. resize ( zlib_estimate_compressed_size (block_size) );
299+ zlib_compress (type, input[b], input_length[b], & compressed[b], true );
303300
304301 auto start = now ();
305302 for (int b = 0 ; b < blocks; ++b)
306303 for (int r = 0 ; r < repeats; ++r)
307304 zlib_compress (type, input[b], input_length[b], &compressed[b]);
308305 ctime[run] = std::chrono::duration<double >(now () - start).count ();
309306
310- // Compress again, resizing compressed, so we don't leave junk at the
311- // end of the compressed string that could confuse zlib_uncompress().
312- for (int b = 0 ; b < blocks; ++b)
313- zlib_compress (type, input[b], input_length[b], &compressed[b], true );
314-
315307 for (int b = 0 ; b < blocks; ++b)
316308 output[b].resize (input_length[b]);
317309
0 commit comments