瀏覽代碼

SDL_rwops.c: stdio_seek - skip API call for RW_SEEK_CUR with 0 offset

Reference Issue #10556.
ds-sloth 1 年之前
父節點
當前提交
2824d138b9
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      src/file/SDL_rwops.c

+ 5 - 1
src/file/SDL_rwops.c

@@ -369,6 +369,7 @@ stdio_size(SDL_RWops * context)
 static Sint64 SDLCALL stdio_seek(SDL_RWops *context, Sint64 offset, int whence)
 static Sint64 SDLCALL stdio_seek(SDL_RWops *context, Sint64 offset, int whence)
 {
 {
     int stdiowhence;
     int stdiowhence;
+    SDL_bool is_noop;
 
 
     switch (whence) {
     switch (whence) {
     case RW_SEEK_SET:
     case RW_SEEK_SET:
@@ -390,7 +391,10 @@ static Sint64 SDLCALL stdio_seek(SDL_RWops *context, Sint64 offset, int whence)
     }
     }
 #endif
 #endif
 
 
-    if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
+    /* don't make a possibly-costly API call for the noop seek from SDL_RWtell */
+    is_noop = (whence == RW_SEEK_CUR) && (offset == 0);
+
+    if (is_noop || fseek(context->hidden.stdio.fp, (fseek_off_t)offset, stdiowhence) == 0) {
         Sint64 pos = ftell(context->hidden.stdio.fp);
         Sint64 pos = ftell(context->hidden.stdio.fp);
         if (pos < 0) {
         if (pos < 0) {
             return SDL_SetError("Couldn't get stream offset");
             return SDL_SetError("Couldn't get stream offset");