- Joined
- Nov 7, 2014
- Messages
- 571
The following functions: DoJASSerStructMagic, DoJASSerInlineMagicF, DoJASSerShadowHelperMagicF, and DoJASSerReturnFixMagicF (in file jasshelper.pas) look pretty much the same:
First, the whole content of the file ('currentmapscript.j') is read, then some magic is done with it (DoXXXMagic(...)), and the result of the "magic" is written to another file ('outputwar3map.j').
For the writing of the 'outputwar3map.j' file, the 'TextFile' type and the functions: 'AssignFile', 'Rewrite', 'Write' and 'Close' are used.
The problem is that 'TextFile's have tiny buffers by default (128 bytes), and writing a lot of bytes using a tiny buffer results in a lot of 'WriteFile' system calls (assuming windows), which is inefficient.
An easy fix would be to add a call to SetTextBuf with a buffer of size > 128 (65536 maybe?) after the call to 'Rewrite(ff2)'.
Code:
procedure DoJASSerStructMagic(f1:string;f2:string;const debug:boolean);overload;
var
ff2:textfile;
bff2:boolean;
i,o:string;
begin
bff2:=false;
try
LoadFile(f1,i);
DoJASSerStructMagic(i,debug,o);
AssignFile(ff2,f2);bff2:=true;
filemode:=fmOpenWrite;
Rewrite(ff2);
Write(ff2,o);
finally
if(bff2) then Close(ff2);
end;
end;
First, the whole content of the file ('currentmapscript.j') is read, then some magic is done with it (DoXXXMagic(...)), and the result of the "magic" is written to another file ('outputwar3map.j').
For the writing of the 'outputwar3map.j' file, the 'TextFile' type and the functions: 'AssignFile', 'Rewrite', 'Write' and 'Close' are used.
The problem is that 'TextFile's have tiny buffers by default (128 bytes), and writing a lot of bytes using a tiny buffer results in a lot of 'WriteFile' system calls (assuming windows), which is inefficient.
An easy fix would be to add a call to SetTextBuf with a buffer of size > 128 (65536 maybe?) after the call to 'Rewrite(ff2)'.