summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pfeifer <daniel@pfeifer-mail.de>2016-09-23 20:04:47 (GMT)
committerDaniel Pfeifer <daniel@pfeifer-mail.de>2016-09-23 20:04:47 (GMT)
commita5a7771a428a1d4a9bb671e56ea6d497361bc753 (patch)
treeb6d3c58dae15fc93a96c29bd0644708e46aa6363
parent6ed564577dd0fffdd7dabfaa0ba14e2518c26048 (diff)
downloadCMake-a5a7771a428a1d4a9bb671e56ea6d497361bc753.zip
CMake-a5a7771a428a1d4a9bb671e56ea6d497361bc753.tar.gz
CMake-a5a7771a428a1d4a9bb671e56ea6d497361bc753.tar.bz2
CTest::CompressString: Reorder code to avoid unnecessary allocation
-rw-r--r--Source/cmCTest.cxx15
1 files changed, 7 insertions, 8 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index d058ca7..0624b52 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -2790,22 +2790,21 @@ bool cmCTest::CompressString(std::string& str)
int ret;
z_stream strm;
- unsigned char* in =
- reinterpret_cast<unsigned char*>(const_cast<char*>(str.c_str()));
- // zlib makes the guarantee that this is the maximum output size
- int outSize =
- static_cast<int>(static_cast<double>(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;
}
+ unsigned char* in =
+ reinterpret_cast<unsigned char*>(const_cast<char*>(str.c_str()));
+ // zlib makes the guarantee that this is the maximum output size
+ int outSize =
+ static_cast<int>(static_cast<double>(str.size()) * 1.001 + 13.0);
+ unsigned char* out = new unsigned char[outSize];
+
strm.avail_in = static_cast<uInt>(str.size());
strm.next_in = in;
strm.avail_out = outSize;