Skip to content

Commit

Permalink
String handling speed optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jval1972 committed Apr 24, 2022
1 parent 041cf08 commit e49a4b2
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Base/c_cmds.pas
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ procedure C_AddCmd(const name: string; proc: cmdproc_t);
exit;
end;

if Pos(CMDSPLITSTR, name) = 0 then
if CharPos(CMDSPLITSTR, name) = 0 then
begin
CMDS[numcmds].name := strupper(name);
CMDS[numcmds].command := proc;
Expand Down
4 changes: 2 additions & 2 deletions Base/c_con.pas
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ procedure C_ExecCommandFile(const filename: string);
readln(t, cmd);
cmd := strtrim(cmd);
if cmd <> '' then
if Pos('//', cmd) <> 1 then
if not Pos1('//', cmd) then
C_ExecuteCmd(cmd);
end;
close(t);
Expand Down Expand Up @@ -750,7 +750,7 @@ procedure C_ExecCommands(const commands: string);
begin
cmd := strtrim(l.Strings[i]);
if cmd <> '' then
if Pos('//', cmd) <> 1 then
if not Pos1('//', cmd) then
C_ExecuteCmd(cmd);
end;
l.Free;
Expand Down
30 changes: 15 additions & 15 deletions Base/deh_base.pas
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ function DEH_NextLine(const s: TDStringList; var str: string; var counter: integ
result := DEH_NextLine(s, str, counter);
exit;
end;
if Pos('#', trimmed) = 1 then
if CharPos('#', trimmed) = 1 then
begin
result := DEH_NextLine(s, str, counter);
exit;
end;
if Pos('//', trimmed) = 1 then // JVAL: Allow // as comments also
if Pos1('//', trimmed) then // JVAL: Allow // as comments also
begin
result := DEH_NextLine(s, str, counter);
exit;
Expand Down Expand Up @@ -313,7 +313,7 @@ procedure DEH_ParseFile(const filename: string);
fnames := TDStringList.Create;
s := TDStringList.Create;
try
if Pos('.', filename) = 0 then
if CharPos('.', filename) = 0 then
begin
fnames.Add('%s.%s', [filename, 'deh']);
fnames.Add('%s.%s', [filename, 'bex']);
Expand Down Expand Up @@ -485,7 +485,7 @@ procedure DEH_SaveCurrentSettings(const fname: string);
exit;
end;

if Pos('.', fname) = 0 then
if CharPos('.', fname) = 0 then
fname1 := fname + '.bex'
else
fname1 := fname;
Expand Down Expand Up @@ -551,7 +551,7 @@ procedure DEH_SaveActordef(const fname: string);
exit;
end;

if Pos('.', fname) = 0 then
if CharPos('.', fname) = 0 then
fname1 := fname + '.txt'
else
fname1 := fname;
Expand Down Expand Up @@ -622,10 +622,10 @@ function DEH_MobjInfoCSV: TDStringList;
headstr := '';
for i := idx1 + 1 to idx2 + 1 do
if strtrim(cs.Strings[i]) <> '' then
if Pos('#', strtrim(cs.Strings[i])) <> 1 then
if not Pos1('#', strtrim(cs.Strings[i])) then
if Pos('//', strtrim(cs.Strings[i])) < 1 then
begin
if Pos('THING ', strtrim(strupper(cs.Strings[i]))) = 1 then
if Pos1('THING ', strtrim(strupper(cs.Strings[i]))) then
begin
if headstr = '' then
headstr := '"id"'
Expand All @@ -646,7 +646,7 @@ function DEH_MobjInfoCSV: TDStringList;
for i := idx1 + 1 to idx2 - 1 do
begin
if strtrim(cs.Strings[i]) <> '' then
if Pos('#', strtrim(cs.Strings[i])) <> 1 then
if not Pos1('#', strtrim(cs.Strings[i])) then
if Pos('//', strtrim(cs.Strings[i])) < 1 then
if Pos('THING ', strtrim(strupper(cs.Strings[i]))) < 1 then
begin
Expand Down Expand Up @@ -681,7 +681,7 @@ procedure DEH_SaveMobjInfoCSV(const fname: string);
exit;
end;

if Pos('.', fname) = 0 then
if CharPos('.', fname) = 0 then
fname1 := fname + '.csv'
else
fname1 := fname;
Expand Down Expand Up @@ -726,10 +726,10 @@ function DEH_StatesCSV: TDStringList;
headstr := '';
for i := idx1 + 1 to idx2 - 1 do
if strtrim(cs.Strings[i]) <> '' then
if Pos('#', strtrim(cs.Strings[i])) <> 1 then
if not Pos1('#', strtrim(cs.Strings[i])) then
if Pos('//', strtrim(cs.Strings[i])) < 1 then
begin
if Pos('FRAME ', strtrim(strupper(cs.Strings[i]))) = 1 then
if Pos1('FRAME ', strtrim(strupper(cs.Strings[i]))) then
begin
if headstr = '' then
headstr := '"Name";"id"'
Expand All @@ -751,9 +751,9 @@ function DEH_StatesCSV: TDStringList;
for i := idx1 + 1 to idx2 - 1 do
begin
if strtrim(cs.Strings[i]) <> '' then
if Pos('#', strtrim(cs.Strings[i])) <> 1 then
if not Pos1('#', strtrim(cs.Strings[i])) then
if Pos('//', strtrim(cs.Strings[i])) < 1 then
if Pos('FRAME ', strtrim(strupper(cs.Strings[i]))) <> 1 then
if not Pos1('FRAME ', strtrim(strupper(cs.Strings[i]))) then
begin
splitstring_ch(strtrim(cs.Strings[i]), s1, s2, '=');
for j := 1 to length(s2) do
Expand Down Expand Up @@ -789,7 +789,7 @@ procedure DEH_SaveStatesCSV(const fname: string);
exit;
end;

if Pos('.', fname) = 0 then
if CharPos('.', fname) = 0 then
fname1 := fname + '.csv'
else
fname1 := fname;
Expand Down Expand Up @@ -842,7 +842,7 @@ procedure DEH_SaveSpritesCSV(const fname: string);
exit;
end;

if Pos('.', fname) = 0 then
if CharPos('.', fname) = 0 then
fname1 := fname + '.csv'
else
fname1 := fname;
Expand Down
2 changes: 1 addition & 1 deletion Base/info_common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function Info_GetMobjNumForAlias(const name: string): integer;
check := strupper(strremovespaces(name)) + '=';
for i := mobjinfo_aliases.Count - 1 downto 0 do
begin
if Pos(check, mobjinfo_aliases.Strings[i]) = 1 then
if Pos1(check, mobjinfo_aliases.Strings[i]) then
begin
splitstring_ch(mobjinfo_aliases.Strings[i], check, snum, '=');
result := atoi(snum);
Expand Down
22 changes: 11 additions & 11 deletions Base/m_misc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ TargaHeader = record
procedure M_FixScreenshotFormat;
begin
screenshotformat := strupper(strtrim(screenshotformat));
if Pos('.', screenshotformat) = 1 then
if CharPos('.', screenshotformat) = 1 then
Delete(screenshotformat, 1, 1);
if screenshotformat = '' then
begin
Expand Down Expand Up @@ -429,14 +429,14 @@ procedure M_ScreenShot(const filename: string = ''; const silent: boolean = fals
pngname := filename + '.png';
end;

if Pos('/', tganame) = 0 then
if Pos('\', tganame) = 0 then
if CharPos('/', tganame) = 0 then
if CharPos('\', tganame) = 0 then
tganame := M_SaveFileName('DATA\SCREENSHOTS\TGA\' + tganame);
if Pos('/', jpgname) = 0 then
if Pos('\', jpgname) = 0 then
if CharPos('/', jpgname) = 0 then
if CharPos('\', jpgname) = 0 then
jpgname := M_SaveFileName('DATA\SCREENSHOTS\JPG\' + jpgname);
if Pos('/', pngname) = 0 then
if Pos('\', pngname) = 0 then
if CharPos('/', pngname) = 0 then
if CharPos('\', pngname) = 0 then
jpgname := M_SaveFileName('DATA\SCREENSHOTS\PNG\' + pngname);
end;

Expand Down Expand Up @@ -513,7 +513,7 @@ procedure Cmd_Set(const name: string; const value: string);
exit;
end;

if pos('*', name) > 0 then // Is a mask
if CharPos('*', name) > 0 then // Is a mask
begin
clist := TDStringList.Create;
try
Expand Down Expand Up @@ -613,7 +613,7 @@ procedure Cmd_Get(const name: string);
exit;
end;

if pos('*', name) > 0 then // Is a mask
if CharPos('*', name) > 0 then // Is a mask
begin
clist := TDStringList.Create;
try
Expand Down Expand Up @@ -692,7 +692,7 @@ procedure Cmd_TypeOf(const name: string);
printf(' Display the type of variable.'#13#10);
end;

if pos('*', name) > 0 then // Is a mask
if CharPos('*', name) > 0 then // Is a mask
begin
clist := TDStringList.Create;
try
Expand Down Expand Up @@ -828,7 +828,7 @@ procedure M_SetDefault(const parm: string);
else
setflags := DFS_SINGLEPLAYER;

if pos('*', parm) > 0 then // Is a mask
if CharPos('*', parm) > 0 then // Is a mask
begin
clist := TDStringList.Create;
try
Expand Down
2 changes: 1 addition & 1 deletion Base/s_pk3sounds.pas
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ procedure S_AddFileName(const filename: string);
check := fname(check);
name := firstword(check, '.');
if Length(name) > 2 then
if Pos('DS', name) = 1 then
if Pos1('DS', name) then
Delete(name, 1, 2);
if Length(name) <= 8 then
if s_names.IndexOf(name) < 0 then
Expand Down
2 changes: 1 addition & 1 deletion Base/sc_engine.pas
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ function SC_RemoveLineQuotes(const sctext: string): string;
p := Pos('//', stmp);
if p > 0 then
stmp := Copy(stmp, 1, p - 1);
p := Pos(';', stmp);
p := CharPos(';', stmp);
if p > 0 then
stmp := Copy(stmp, 1, p - 1);
if stmp <> '' then
Expand Down
10 changes: 5 additions & 5 deletions Base/sc_states.pas
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ function P_GetStateFromName(const actor: Pmobj_t; const s1: string): integer;
begin
s := SC_EvalString(s1);
st := strtrim(strupper(strtrim(s)));
pps := Pos('+', st);
ppp := Pos('-', st);
ppb := Pos(' ', st);
pps := CharPos('+', st);
ppp := CharPos('-', st);
ppb := CharPos(' ', st);
if (ppb = 0) and (ppp = 0) and (pps = 0) then
begin
Result := _stindex(st);
Expand All @@ -288,8 +288,8 @@ function P_GetStateFromName(const actor: Pmobj_t; const s1: string): integer;
// 20191003 rewritten, fixed
begin
st := strremovespaces(st);
pps := Pos('+', st);
ppp := Pos('-', st);
pps := CharPos('+', st);
ppp := CharPos('-', st);
if pps > 0 then
begin
splitstring_ch(st, fw, sw, '+');
Expand Down
2 changes: 1 addition & 1 deletion Base/vx_voxelsprite.pas
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ function VX_SpriteExistsInWAD(const filename: string): boolean;
in_loop := false
else if in_loop then
begin
if Pos(check, lumpname) = 1 then
if Pos1(check, lumpname) then
begin
result := true;
exit;
Expand Down
4 changes: 2 additions & 2 deletions Base/w_pak.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,11 @@ function TPakManager.POpenFileNameWithDirectory(var F: TPakFile; Name: string):

Name := fixpathname(Name);

p := Pos('\', Name);
p := CharPos('\', Name);
if p = 1 then
begin
Delete(Name, 1, 1);
p := Pos('\', Name);
p := CharPos('\', Name);
end;
if p = 0 then
Exit;
Expand Down
2 changes: 1 addition & 1 deletion Base/w_utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ procedure W_CmdSaveLumpToDisk(const lumpname: string; const filename: string);
exit;
end;

if Pos('.', filename) = 0 then
if CharPos('.', filename) = 0 then
fname := filename + '.lmp'
else
fname := filename;
Expand Down
14 changes: 7 additions & 7 deletions Common/d_delphi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1616,9 +1616,9 @@ function atoi(const s: string): integer;
if code <> 0 then
begin
ret2 := 0;
if Pos('0x', s) = 1 then
if Pos1('0x', s) then
val('$' + Copy(s, 3, Length(s) - 2), ret2, code)
else if Pos('-0x', s) = 1 then
else if Pos1('-0x', s) then
begin
val('$' + Copy(s, 4, Length(s) - 3), ret2, code);
ret2 := -ret2;
Expand Down Expand Up @@ -1646,9 +1646,9 @@ function atoi(const s: string; const default: integer): integer; overload;
if code <> 0 then
begin
ret2 := default;
if Pos('0x', s) = 1 then
if Pos1('0x', s) then
val('$' + Copy(s, 3, Length(s) - 2), ret2, code)
else if Pos('-0x', s) = 1 then
else if Pos1('-0x', s) then
begin
val('$' + Copy(s, 4, Length(s) - 3), ret2, code);
ret2 := -ret2;
Expand Down Expand Up @@ -1676,7 +1676,7 @@ function atoui(const s: string): LongWord; overload;
if code <> 0 then
begin
ret2 := 0;
if Pos('0x', s) = 1 then
if Pos1('0x', s) then
val('$' + Copy(s, 3, Length(s) - 2), ret2, code)
else if CharPos('#', s) = 1 then
val(Copy(s, 2, Length(s) - 1), ret2, code);
Expand All @@ -1701,7 +1701,7 @@ function atoui(const s: string; const default: LongWord): LongWord; overload;
if code <> 0 then
begin
ret2 := default;
if Pos('0x', s) = 1 then
if Pos1('0x', s) then
val('$' + Copy(s, 3, Length(s) - 2), ret2, code)
else if CharPos('#', s) = 1 then
val(Copy(s, 2, Length(s) - 1), ret2, code);
Expand Down Expand Up @@ -6846,7 +6846,7 @@ function readablestring(const s: string): string;
h := '0123456789ABCDEF';
for i := 1 to Length(s) do
begin
if Pos(toupper(s[i]), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') > 0 then
if CharPos(toupper(s[i]), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') > 0 then
result := result + toupper(s[i])
else
result := result + h[Ord(s[i]) div 16 + 1] + h[Ord(s[i]) mod 16 + 1];
Expand Down
Loading

0 comments on commit e49a4b2

Please sign in to comment.