1
0
mirror of https://github.com/luanti-org/minetestmapper.git synced 2025-10-05 21:35:22 +02:00

Some more code modernization

also a few small performance improvements
This commit is contained in:
sfan5
2020-05-08 22:10:49 +02:00
parent 2979dc5b6b
commit 8e83ce6464
21 changed files with 149 additions and 199 deletions

View File

@@ -1,12 +1,3 @@
/*
* =====================================================================
* Version: 1.0
* Created: 18.09.2012 10:20:47
* Author: Miroslav Bendík
* Company: LinuxOS.sk
* =====================================================================
*/
#include <zlib.h>
#include <stdint.h>
#include "ZlibDecompressor.h"
@@ -38,8 +29,8 @@ ustring ZlibDecompressor::decompress()
const std::size_t size = m_size - m_seekPos;
ustring buffer;
const size_t BUFSIZE = 128 * 1024;
uint8_t temp_buffer[BUFSIZE];
constexpr size_t BUFSIZE = 128 * 1024;
unsigned char temp_buffer[BUFSIZE];
z_stream strm;
strm.zalloc = Z_NULL;
@@ -48,9 +39,8 @@ ustring ZlibDecompressor::decompress()
strm.next_in = Z_NULL;
strm.avail_in = size;
if (inflateInit(&strm) != Z_OK) {
if (inflateInit(&strm) != Z_OK)
throw DecompressError();
}
strm.next_in = const_cast<unsigned char *>(data);
int ret = 0;
@@ -58,11 +48,11 @@ ustring ZlibDecompressor::decompress()
strm.avail_out = BUFSIZE;
strm.next_out = temp_buffer;
ret = inflate(&strm, Z_NO_FLUSH);
buffer += ustring(reinterpret_cast<unsigned char *>(temp_buffer), BUFSIZE - strm.avail_out);
buffer.append(temp_buffer, BUFSIZE - strm.avail_out);
} while (ret == Z_OK);
if (ret != Z_STREAM_END) {
if (ret != Z_STREAM_END)
throw DecompressError();
}
m_seekPos += strm.next_in - data;
(void)inflateEnd(&strm);