The attached patch is only version 1 (don't commit it yet, its not
thoroughly tested and I want to spend some more time and make more
changes until I call it ready for production).
I did some poor-man's profiling with the chm viewer lhelp (hit pause
during the slowness look at the callstack, catch it in the act, repeat
this a few times [effectively the same thing that a sampling profiler
like oprofile would do]). During scrolling of long pages it seemed to
spend a lot (almost all) of its time in the same procedure, looking up
css property names in a TStringList with IndexOf().
TStringList.IndexOf() does a linear search, so I thought why not
replace this with a TFPObjectHashTable. All it has to do is store a
list of objects by name and all it is needed for is looking them up by
name thousands and thousands of times.
After doing this (see the attached patch, its only a few lines) the
scrolling seems a hundred times faster! Really! Try it with rtl.chm
and look up the help for Format(), its a very long page, it was
basically unscrollable before. I'm totally excited! This is the first
time I have seen lhelp being actually usable! This is the reason I
could not wait to post this patch.
I'm now going to see if I can find a few more TStringlists to replace this way.
Bernd
Index: components/turbopower_ipro/ipcss.inc
===================================================================
--- components/turbopower_ipro/ipcss.inc (Revision 34379)
+++ components/turbopower_ipro/ipcss.inc (Arbeitskopie)
@@ -96,7 +96,7 @@
{ TCSSGlobalProps }
TCSSGlobalProps = class
- FElements: TStringList;
+ FElements: TFPObjectHashTable;
public
constructor Create;
destructor Destroy; override;
@@ -482,6 +482,7 @@
end;
end;
+
{ TCSSReader }
function TCSSReader.GetStatementElements(AStatement: String): TStringList;
@@ -870,15 +871,13 @@
constructor TCSSGlobalProps.Create;
begin
- FElements := TStringList.Create;
+ FElements := TFPObjectHashTable.Create(True);
end;
destructor TCSSGlobalProps.Destroy;
var
i: Integer;
begin
- for i := 0 to FElements.Count-1 do
- FElements.Objects[i].Free;
FElements.Free;
inherited Destroy;
end;
@@ -889,21 +888,14 @@
ElementName: String;
procedure LookForElement(const aElement: string);
- var
- ElementIndex: Integer;
begin
if length(ClassID) > 0 then
ElementName := Lowercase(aElement+'.'+ClassId)
else
ElementName := lowercase(aElement);
-
- ElementIndex := FElements.IndexOf(ElementName);
-
- if ElementIndex>=0 then begin
- result := TCSSProps(FElements.Objects[ElementIndex]);
- end;
-
+ Result := TCSSProps(FElements.Items[ElementName]);
end;
+
begin
Result := nil;
if (length(ClassID) = 0) and (length(AElementID) = 0) then
@@ -916,7 +908,7 @@
if (Result = nil) and CreateIfNotExist then
begin
Result := TCSSProps.Create;
- FElements.AddObject(ElementName, Result);
+ FElements.Add(ElementName, Result);
end;
end;
Index: components/turbopower_ipro/iphtml.pas
===================================================================
--- components/turbopower_ipro/iphtml.pas (Revision 34379)
+++ components/turbopower_ipro/iphtml.pas (Arbeitskopie)
@@ -69,6 +69,7 @@
Messages,
SysUtils,
Classes,
+ contnrs,
Graphics,
{$IFDEF IP_LAZARUS} //JMN
{$IFDEF UseGifImageUnit}
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus