diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-20 17:40:06 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-20 17:40:06 +0100 |
commit | 82f1d8146072b8b8470f0d09374c7092da35c71a (patch) | |
tree | ed940adbefb34a6d0eef071e9109bfad7960c984 | |
parent | 51b0c3239265ddee2d1bf445f873299cc8193ab9 (diff) | |
download | mana-82f1d8146072b8b8470f0d09374c7092da35c71a.tar.gz mana-82f1d8146072b8b8470f0d09374c7092da35c71a.tar.bz2 mana-82f1d8146072b8b8470f0d09374c7092da35c71a.tar.xz mana-82f1d8146072b8b8470f0d09374c7092da35c71a.zip |
Simplified filling of the BufferedRWops buffer
In fact filling the buffer only happens when the buffer was exhausted
or empty, so we always want to fill it entirely and don't need to bother
with moving remaining contents.
This is what happens when you let AI write your code.
-rw-r--r-- | src/utils/bufferedrwops.c | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/src/utils/bufferedrwops.c b/src/utils/bufferedrwops.c index 441b477c..e12f8b5b 100644 --- a/src/utils/bufferedrwops.c +++ b/src/utils/bufferedrwops.c @@ -31,27 +31,6 @@ typedef struct BufferedRWops { Uint8 buffer[BUFFER_SIZE]; // Our read-ahead buffer } BufferedRWops; -static void fillBuffer(BufferedRWops* br) { - // If there's still data in the buffer, move it to the start - if (br->bufferPos < br->bufferFill) { - size_t remaining = br->bufferFill - br->bufferPos; - memmove(br->buffer, br->buffer + br->bufferPos, remaining); - br->bufferFill = remaining; - } else { - br->bufferFill = 0; - } - br->bufferPos = 0; - - // Fill the rest of the buffer - size_t space = BUFFER_SIZE - br->bufferFill; - if (space > 0) { - size_t read = SDL_RWread(br->source, - br->buffer + br->bufferFill, - 1, space); - br->bufferFill += read; - } -} - static Sint64 SDLCALL buffered_size(SDL_RWops* context) { BufferedRWops* br = (BufferedRWops*)context->hidden.unknown.data1; return SDL_RWsize(br->source); @@ -132,8 +111,11 @@ static size_t SDLCALL buffered_read(SDL_RWops* context, void* dst, size_t size, break; // Nothing more to read } - fillBuffer(br); - if (br->bufferFill == 0) break; // EOF or error + br->bufferPos = 0; + br->bufferFill = SDL_RWread(br->source, br->buffer, 1, BUFFER_SIZE); + + if (br->bufferFill == 0) + break; // EOF or error } // Copy what we can from the buffer |