mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Saveload: Move AcquireBytes loop out of CheckBytes
This commit is contained in:
parent
0ab976e069
commit
d0cbc48f7d
@ -139,18 +139,24 @@ void ReadBuffer::SkipBytesSlowPath(size_t bytes)
|
||||
}
|
||||
}
|
||||
|
||||
void ReadBuffer::AcquireBytes()
|
||||
void ReadBuffer::AcquireBytes(size_t bytes)
|
||||
{
|
||||
size_t remainder = this->bufe - this->bufp;
|
||||
if (remainder) {
|
||||
memmove(this->buf, this->bufp, remainder);
|
||||
}
|
||||
size_t len = this->reader->Read(this->buf + remainder, lengthof(this->buf) - remainder);
|
||||
if (len == 0) SlErrorCorrupt("Unexpected end of chunk");
|
||||
size_t total = remainder;
|
||||
size_t target = remainder + bytes;
|
||||
do {
|
||||
size_t len = this->reader->Read(this->buf + total, lengthof(this->buf) - total);
|
||||
if (len == 0) SlErrorCorrupt("Unexpected end of chunk");
|
||||
|
||||
this->read += len;
|
||||
total += len;
|
||||
} while (total < target);
|
||||
|
||||
this->read += total - remainder;
|
||||
this->bufp = this->buf;
|
||||
this->bufe = this->buf + remainder + len;
|
||||
this->bufe = this->buf + total;
|
||||
}
|
||||
|
||||
void MemoryDumper::FinaliseBlock()
|
||||
|
@ -106,7 +106,7 @@ struct ReadBuffer {
|
||||
static ReadBuffer *GetCurrent();
|
||||
|
||||
void SkipBytesSlowPath(size_t bytes);
|
||||
void AcquireBytes();
|
||||
void AcquireBytes(size_t bytes = 0);
|
||||
|
||||
inline void SkipBytes(size_t bytes)
|
||||
{
|
||||
@ -138,7 +138,7 @@ struct ReadBuffer {
|
||||
|
||||
inline void CheckBytes(size_t bytes)
|
||||
{
|
||||
while (unlikely(this->bufp + bytes > this->bufe)) this->AcquireBytes();
|
||||
if (unlikely(this->bufp + bytes > this->bufe)) this->AcquireBytes(bytes);
|
||||
}
|
||||
|
||||
inline RawReadBuffer ReadRawBytes(size_t bytes)
|
||||
|
Loading…
Reference in New Issue
Block a user