1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-02-03 04:05:49 +01:00

FileStream::Read: Throw the exception basing on fread return value

This change removes ftell/GetPosition() from hot spots during the startup,
"optimizing" the function for success cases - reading past EOF should
never/rarely happen so it seems fine to let it try to read before checking
This commit is contained in:
Silent
2021-05-21 18:51:00 +02:00
parent 724a3c0579
commit e280eb2083

View File

@@ -165,13 +165,9 @@ namespace OpenRCT2
void FileStream::Read(void* buffer, uint64_t length)
{
uint64_t remainingBytes = GetLength() - GetPosition();
if (length <= remainingBytes)
if (fread(buffer, 1, static_cast<size_t>(length), _file) == length)
{
if (fread(buffer, static_cast<size_t>(length), 1, _file) == 1)
{
return;
}
return;
}
throw IOException("Attempted to read past end of file.");
}