From a5a7771a428a1d4a9bb671e56ea6d497361bc753 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Fri, 23 Sep 2016 22:04:47 +0200 Subject: [PATCH] CTest::CompressString: Reorder code to avoid unnecessary allocation --- Source/cmCTest.cxx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index d058ca74e..0624b525d 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2790,6 +2790,14 @@ bool cmCTest::CompressString(std::string& str) int ret; z_stream strm; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + ret = deflateInit(&strm, -1); // default compression level + if (ret != Z_OK) { + return false; + } + unsigned char* in = reinterpret_cast(const_cast(str.c_str())); // zlib makes the guarantee that this is the maximum output size @@ -2797,15 +2805,6 @@ bool cmCTest::CompressString(std::string& str) static_cast(static_cast(str.size()) * 1.001 + 13.0); unsigned char* out = new unsigned char[outSize]; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - ret = deflateInit(&strm, -1); // default compression level - if (ret != Z_OK) { - delete[] out; - return false; - } - strm.avail_in = static_cast(str.size()); strm.next_in = in; strm.avail_out = outSize;