Add a persistentChunks flag to SawyerChunkReader

New behaviour of SawyerChunkReader is to skip shrinking the chunk
memory unless persistentChunks is set to true. At the moment all uses
of SawyerChunks created by the reader are temporary and shrinking memory
right before freeing them is a waste of time.

Speeds up loading times and index building
This commit is contained in:
Silent 2021-05-22 15:26:59 +02:00
parent fb602ec0c9
commit 66abc69690
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
3 changed files with 15 additions and 6 deletions

View File

@ -21,7 +21,7 @@
- Fix: [#14604] American-style Steam Trains are not imported correctly from RCT1 saves.
- Fix: [#14638] The “About OpenRCT2” window cannot be themed.
- Fix: [#14710] Ride/Track Design preview does not show if it costs more money than available.
- Improved: [#14712]: Improve startup times.
- Improved: [#14712, #14716]: Improve startup times.
0.3.3 (2021-03-13)
------------------------------------------------------------------------

View File

@ -27,8 +27,9 @@ constexpr const char* EXCEPTION_MSG_DESTINATION_TOO_SMALL = "Chunk data larger t
constexpr const char* EXCEPTION_MSG_INVALID_CHUNK_ENCODING = "Invalid chunk encoding.";
constexpr const char* EXCEPTION_MSG_ZERO_SIZED_CHUNK = "Encountered zero-sized chunk.";
SawyerChunkReader::SawyerChunkReader(OpenRCT2::IStream* stream)
SawyerChunkReader::SawyerChunkReader(OpenRCT2::IStream* stream, bool persistentChunks)
: _stream(stream)
, _createsPersistentChunks(persistentChunks)
{
}
@ -78,7 +79,10 @@ std::shared_ptr<SawyerChunk> SawyerChunkReader::ReadChunk()
{
throw SawyerChunkException(EXCEPTION_MSG_ZERO_SIZED_CHUNK);
}
buffer = static_cast<uint8_t*>(FinaliseLargeTempBuffer(buffer, uncompressedLength));
if (_createsPersistentChunks)
{
buffer = static_cast<uint8_t*>(FinaliseLargeTempBuffer(buffer, uncompressedLength));
}
return std::make_shared<SawyerChunk>(
static_cast<SAWYER_ENCODING>(header.encoding), buffer, uncompressedLength);
}
@ -126,7 +130,10 @@ std::shared_ptr<SawyerChunk> SawyerChunkReader::ReadChunkTrack()
{
throw SawyerChunkException(EXCEPTION_MSG_ZERO_SIZED_CHUNK);
}
buffer = static_cast<uint8_t*>(FinaliseLargeTempBuffer(buffer, uncompressedLength));
if (_createsPersistentChunks)
{
buffer = static_cast<uint8_t*>(FinaliseLargeTempBuffer(buffer, uncompressedLength));
}
return std::make_shared<SawyerChunk>(SAWYER_ENCODING::RLE, buffer, uncompressedLength);
}
catch (const std::exception&)

View File

@ -36,15 +36,17 @@ namespace OpenRCT2
/**
* Reads sawyer encoding chunks from a data stream. This can be used to read
* SC6, SV6 and RCT2 objects.
* SC6, SV6 and RCT2 objects. persistentChunks is a hint to the reader that the chunk will be preserved,
* and thus the chunk memory should be shrunk.
*/
class SawyerChunkReader final
{
private:
OpenRCT2::IStream* const _stream = nullptr;
const bool _createsPersistentChunks = false;
public:
explicit SawyerChunkReader(OpenRCT2::IStream* stream);
explicit SawyerChunkReader(OpenRCT2::IStream* stream, bool persistentChunks = false);
/**
* Skips the next chunk in the stream without decoding or reading its data