Skip to content

Commit 283871f

Browse files
committed
Use fstat to access the current file size of a FilePlugin file on unices.
This is much faster than the old seek method. e.g. on a 2021 MBP with an SSD running Sequoia 15.6.1 | f fid | fid := (f := SourceFiles at: 1) fileID. [f primSize: fid] bench answers '654,000 per second. 1.53 microseconds per run. 0 % GC time.' using the old seek here, seek end, seek here method, but answers '2,410,000 per second. 414 nanoseconds per run. 0 % GC time.' using the new fstat method.
1 parent 81d66a6 commit 283871f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ static squeakFileOffsetType
130130
getSize(SQFile *f)
131131
{
132132
FILE *file = getFile(f);
133+
# if !defined(NO_STD_FILE_SUPPORT)
134+
struct stat buf;
135+
136+
if (!fstat(fileno(file),&buf))
137+
return buf.st_size;
138+
#endif
133139
squeakFileOffsetType currentPosition = ftello(file);
134140
fseeko(file, 0, SEEK_END);
135141
squeakFileOffsetType size = ftello(file);

0 commit comments

Comments
 (0)