1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-13 11:02:47 +01:00

Speedup calculate_checksum by ~9%

Skips unnecessary `rol32`s
This commit is contained in:
Michał Janiszewski
2016-12-28 19:31:56 +01:00
committed by GitHub
parent d15112dcb3
commit ab43bf74d5

View File

@@ -932,7 +932,7 @@ extern "C"
int object_calculate_checksum(const rct_object_entry * entry, const void * data, size_t dataLength)
{
const uint8 *entryBytePtr = (uint8*)entry;
const uint8 * entryBytePtr = (uint8 *)entry;
uint32 checksum = 0xF369A75B;
checksum ^= entryBytePtr[0];
@@ -944,7 +944,16 @@ extern "C"
}
uint8 * dataBytes = (uint8 *)data;
for (size_t i = 0; i < dataLength; i++)
const size_t dataLength32 = dataLength - (dataLength & 31);
for (size_t i = 0; i < 32; i++)
{
for (size_t j = i; j < dataLength32; j += 32)
{
checksum ^= dataBytes[j];
}
checksum = rol32(checksum, 11);
}
for (size_t i = dataLength32; i < dataLength; i++)
{
checksum ^= dataBytes[i];
checksum = rol32(checksum, 11);