mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-30 18:00:43 +02:00
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 -
This commit is contained in:
parent
b0c7415f3a
commit
3d2fca152b
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user