Originally Posted by
jdarling
I just profiled my game engine and I'm spending about 80% of my time inside of the TStringList
. I knew it would be bad, but not that bad. Anyone know of a good fast StringList replacement?
Hi Jeremy,
You may want to try this... it improved the performance of our web server system slightly. Its easy enough to switch to since its a drop in replacement.
If you do give it a go, I'd be interested to know what kind of performance it offers.
Code:
unit faststringlist;
(*------------------------------------------------------------
Fast String List
Description:-
This unit provides an enhanced string list
See Also:-
Version History:-
Date Version Label Author Description
========== ======= ===== ====== ===========================================
Jan 06 0.0 Starting Version uses code from a couple of
places. Overriden 'find' is an addition (removed)
------------------------------------------------------------*)
interface
uses
classes;
type
TFastStringList = class(TStringList)
protected
fAssigning : boolean;
public
constructor create;
procedure sort; override;
procedure assign(source:TPersistent); override;
function indexOf(const s:string):integer; override;
end;
(*------------------------------------------------------------*)
implementation
uses
sysUtils;
(* Fast String List - From RiverSoftAVG's hints/tips section *)
constructor TFastStringList.create;
begin
inherited;
fAssigning:=false;
end;
procedure TFastStringList.Assign( Source: TPersistent );
begin
if Sorted and
(Source is TStringList) and
(TStringList(Source).Sorted) then
begin
BeginUpdate;
try
Sorted := False;
FAssigning := True;
inherited Assign( Source );
finally
Sorted := True;
FAssigning := False;
EndUpdate;
end;
end
else
inherited Assign( Source );
end;
procedure TFastStringList.Sort;
begin
if not FAssigning then
inherited Sort;
end;
function TFastStringList.IndexOf(const S: string): Integer;
begin
if not Sorted then
begin
for Result := 0 to Count - 1 do
if CompareText(Strings[Result], S) = 0 then Exit;
Result := -1;
end
else if not Find(S, Result) then
Result := -1;
end;
end.
Bookmarks