CTest::CompressString: Reorder code to avoid unnecessary allocation
This commit is contained in:
parent
6ed564577d
commit
a5a7771a42
|
@ -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<unsigned char*>(const_cast<char*>(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<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;
|
||||
}
|
||||
|
||||
strm.avail_in = static_cast<uInt>(str.size());
|
||||
strm.next_in = in;
|
||||
strm.avail_out = outSize;
|
||||
|
|
Loading…
Reference in New Issue