diff options
author | Daniel Pfeifer <daniel@pfeifer-mail.de> | 2016-09-23 20:04:47 (GMT) |
---|---|---|
committer | Daniel Pfeifer <daniel@pfeifer-mail.de> | 2016-09-23 20:04:47 (GMT) |
commit | a5a7771a428a1d4a9bb671e56ea6d497361bc753 (patch) | |
tree | b6d3c58dae15fc93a96c29bd0644708e46aa6363 | |
parent | 6ed564577dd0fffdd7dabfaa0ba14e2518c26048 (diff) | |
download | CMake-a5a7771a428a1d4a9bb671e56ea6d497361bc753.zip CMake-a5a7771a428a1d4a9bb671e56ea6d497361bc753.tar.gz CMake-a5a7771a428a1d4a9bb671e56ea6d497361bc753.tar.bz2 |
CTest::CompressString: Reorder code to avoid unnecessary allocation
-rw-r--r-- | Source/cmCTest.cxx | 15 |
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; |