Browse Source

amicommon: a better, faster implementation of do_filesize(). since it no longer seeks, speed should be constant and not depend on the filesize and underlying FS fragmentation, among others

git-svn-id: trunk@29379 -
Károly Balogh 10 years ago
parent
commit
3d2fca152b
1 changed files with 26 additions and 2 deletions
  1. 26 2
      rtl/amicommon/sysfile.inc

+ 26 - 2
rtl/amicommon/sysfile.inc

@@ -278,17 +278,41 @@ begin
   end;
 end;
 
+{$DEFINE ASYS_FILESIZE_NO_DOUBLE_SEEK}
+{ I changed the double-Seek filesize method which we
+  were using for 10+ years to the new ExamineFH() method.
+  It should be available AmigaOS 2.0+, and much faster.
+
+  (I actually measured several magnitudes of improvement,
+  especially on large files.)
+
+  It should be safe since there are several libc implementations
+  using the same method on all Amiga flavors, but if anyone has
+  a problem with it, disable this define to revert to the old
+  method and report the issue. (KB) } 
 function do_filesize(handle : longint) : longint;
-var currfilepos: longint;
+var
+{$IFDEF ASYS_FILESIZE_NO_DOUBLE_SEEK}
+  fib: PFileInfoBlock;
+{$ENDIF}
+  currfilepos: longint;
 begin
   checkCTRLC;
   do_filesize:=-1;
   if CheckInList(ASYS_fileList,handle)<>nil then begin
 
+{$IFDEF ASYS_FILESIZE_NO_DOUBLE_SEEK}
+    fib:=AllocDosObject(DOS_FIB,nil);
+    if fib <> nil then begin
+      if ExamineFH(handle, fib) then
+        do_filesize:=fib^.fib_Size;
+      FreeDosObject(DOS_FIB,fib);
+    end;
+{$ELSE}
     currfilepos:=do_filepos(handle);
     do_filesize:=do_seekend(handle);
     do_seek(handle,currfilepos);
-
+{$ENDIF}
   end;
 end;