[Oberon] Shortening Files.WriteBuf
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Sun Jan 8 20:38:47 CET 2023
When rewriting Files.Mod to allow for arbitrarily large file sizes while simultaneously maintaining a very low memory footprint in f.ext (and a new f.dbl), I bumped into some code in Files.Mod that seems unnecessary (i.e. removing it does nothing to the system)
Does anyone see any strong reason why one CANNOT shorten Files. WriteBuf
From:
PROCEDURE WriteBuf(f: File; buf: Buffer);
VAR i, k: INTEGER;
secadr: DiskAdr; inx: Index;
BEGIN
IF buf.apos < STS THEN
secadr := f.sec[buf.apos];
IF secadr = 0 THEN
Disk.AllocSector(f.sechint, secadr);
f.modH := TRUE; f.sec[buf.apos] := secadr; f.sechint := secadr
END ;
IF buf.apos = 0 THEN
UpdateHeader(f, SYSTEM.VAL(FileDir.FileHeader, buf.data)); f.modH := FALSE
END
ELSE i := (buf.apos - STS) DIV XS; inx := f.ext[i];
IF inx = NIL THEN
NEW(inx); inx.adr := 0; inx.sec[0] := 0; f.ext[i] := inx; f.modH := TRUE
END ;
k := (buf.apos - STS) MOD XS; secadr := inx.sec[k];
IF secadr = 0 THEN
Disk.AllocSector(f.sechint, secadr);
f.modH := TRUE; inx.mod := TRUE; inx.sec[k] := secadr; f.sechint := secadr
END
END ;
Disk.PutSector(secadr, buf.data); buf.mod := FALSE
END WriteBuf;
To
PROCEDURE WriteBuf(f: File; buf: Buffer);
VAR i: INTEGER;
secadr: DiskAdr; inx: Index;
BEGIN
IF buf.apos < STS THEN
secadr := f.sec[buf.apos];
IF secadr = 0 THEN
Disk.AllocSector(f.sechint, secadr);
f.modH := TRUE; f.sec[buf.apos] := secadr; f.sechint := secadr
END ;
IF buf.apos = 0 THEN
UpdateHeader(f, SYSTEM.VAL(FileDir.FileHeader, buf.data)); f.modH := FALSE
END
ELSE inx := f.ext[(buf.apos - STS) DIV XS];
i := (buf.apos - STS) MOD XS; secadr := inx.sec[i];
IF secadr = 0 THEN
Disk.AllocSector(f.sechint, secadr);
inx.mod := TRUE; inx.sec[i] := secadr; f.sechint := secadr
END
END ;
Disk.PutSector(secadr, buf.data); buf.mod := FALSE
END WriteBuf;
?
Two changes were made:
1) the code IF inx = NIL THEN .. END is removed - since the in-memory data structure rooted in f.ext[i] can only ever grow in Files.NewExt)
2) the assignment f.modH in the last IF statement of Files.WriteBuf is removed - as this is handled by IF inx.mod THEN .. END in Files.Unbuffer
More information about the Oberon
mailing list