mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-25 01:59:14 +02:00
IconFinder: Inherit TIconList from TFPHashObjectList rather than TFPGObjectList to speed up TThumbnailViewer.ReadMetadata by factor 2.
(cherry picked from commit 25a1a645ec
)
This commit is contained in:
parent
e15e3cf85e
commit
f2d4c42e2f
@ -13,11 +13,12 @@ unit IconThumbNails;
|
|||||||
|
|
||||||
{$mode ObjFPC}{$H+}
|
{$mode ObjFPC}{$H+}
|
||||||
{$define OVERLAY_ICONS}
|
{$define OVERLAY_ICONS}
|
||||||
|
{$define SPEED_TIMER}
|
||||||
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
|
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fgl, FPImage, StrUtils, LazLoggerBase,
|
Classes, SysUtils, fgl, contnrs, FPImage, StrUtils, LazLoggerBase,
|
||||||
laz2_dom, laz2_xmlread, laz2_xmlwrite,
|
laz2_dom, laz2_xmlread, laz2_xmlwrite,
|
||||||
FileUtil, LazFileUtils, Graphics, Controls, Dialogs, Menus, Forms,
|
FileUtil, LazFileUtils, Graphics, Controls, Dialogs, Menus, Forms,
|
||||||
IconFinderStrConsts, BasicThumbnails;
|
IconFinderStrConsts, BasicThumbnails;
|
||||||
@ -84,9 +85,13 @@ type
|
|||||||
property Width: Integer read FWidth;
|
property Width: Integer read FWidth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TIconList = class(specialize TFPGObjectList<TIconItem>)
|
TIconList = class(TFPHashObjectList)
|
||||||
|
private
|
||||||
|
function GetItem(AIndex: Integer): TIconItem;
|
||||||
|
procedure SetItem(AIndex: Integer; AValue: TIconItem);
|
||||||
public
|
public
|
||||||
function IndexOfFileName(AFileName: String): Integer;
|
function IndexOfFileName(AFileName: String): Integer;
|
||||||
|
property Items[AIndex: Integer]: TIconItem read GetItem write SetItem; default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TIconFolderItem = class
|
TIconFolderItem = class
|
||||||
@ -192,7 +197,6 @@ function StrToIconStyle(AText: String): TIconStyle;
|
|||||||
const
|
const
|
||||||
IMAGES_MASK = '*.png;*.bmp';
|
IMAGES_MASK = '*.png;*.bmp';
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$ifdef OVERLAY_ICONS}
|
{$ifdef OVERLAY_ICONS}
|
||||||
@ -436,21 +440,19 @@ end;
|
|||||||
|
|
||||||
{ TIconList }
|
{ TIconList }
|
||||||
|
|
||||||
|
function TIconList.GetItem(AIndex: Integer): TIconItem;
|
||||||
|
begin
|
||||||
|
Result := TIconItem(inherited Items[AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
function TIconList.IndexOfFileName(AFileName: String): Integer;
|
function TIconList.IndexOfFileName(AFileName: String): Integer;
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
item: TIconItem;
|
|
||||||
begin
|
begin
|
||||||
for i := 0 to Count-1 do
|
Result := FindIndexOf(AFileName);
|
||||||
begin
|
|
||||||
item := Items[i];
|
|
||||||
if item.FileName = AFileName then
|
|
||||||
begin
|
|
||||||
Result := i;
|
|
||||||
exit;
|
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
Result := -1;
|
procedure TIconList.SetItem(AIndex: Integer; AValue: TIconItem);
|
||||||
|
begin
|
||||||
|
inherited Items[AIndex] := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -683,7 +685,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
Result := TIconItem.Create(AFileName, AKeywords, AStyle, AWidth, AHeight);
|
Result := TIconItem.Create(AFileName, AKeywords, AStyle, AWidth, AHeight);
|
||||||
Result.FViewer := Self;
|
Result.FViewer := Self;
|
||||||
FIconList.Add(Result);
|
FIconList.Add(AFileName, Result);
|
||||||
end else
|
end else
|
||||||
Result := FIconList[idx];
|
Result := FIconList[idx];
|
||||||
|
|
||||||
@ -730,7 +732,7 @@ begin
|
|||||||
for i := 0 to FIconList.Count-1 do
|
for i := 0 to FIconList.Count-1 do
|
||||||
begin
|
begin
|
||||||
item := FIconList[i];
|
item := FIconList[i];
|
||||||
itemDir := FIconList[i].Directory;
|
itemDir := item.Directory;
|
||||||
if SameText(iconNameBase, item.NameBase) and SameText(iconDir, itemDir) and (item <> AIcon) then
|
if SameText(iconNameBase, item.NameBase) and SameText(iconDir, itemDir) and (item <> AIcon) then
|
||||||
item.CopyMetadataFrom(AIcon);
|
item.CopyMetadataFrom(AIcon);
|
||||||
end;
|
end;
|
||||||
@ -1164,7 +1166,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIconThumbnailViewer.ReadMetadataFile(AFileName: String; AHidden: Boolean);
|
procedure TIconThumbnailViewer.ReadMetadataFile(AFileName: String;
|
||||||
|
AHidden: Boolean);
|
||||||
var
|
var
|
||||||
doc: TXMLDocument = nil;
|
doc: TXMLDocument = nil;
|
||||||
iconsNode, iconNode: TDOMNode;
|
iconsNode, iconNode: TDOMNode;
|
||||||
@ -1175,10 +1178,16 @@ var
|
|||||||
style: TIconStyle;
|
style: TIconStyle;
|
||||||
s: String;
|
s: String;
|
||||||
keywords: String;
|
keywords: String;
|
||||||
files: TStringList;
|
files: TStringList = nil;
|
||||||
stream: TStream;
|
stream: TStream;
|
||||||
reader: TFPCustomImageReaderClass;
|
reader: TFPCustomImageReaderClass;
|
||||||
|
{$ifdef SPEED_TIMER}
|
||||||
|
t1, t2: TDateTime;
|
||||||
|
{$endif}
|
||||||
begin
|
begin
|
||||||
|
{$ifdef SPEED_TIMER}
|
||||||
|
t1 := Now();
|
||||||
|
{$endif}
|
||||||
folder := ExtractFilePath(AFileName);
|
folder := ExtractFilePath(AFileName);
|
||||||
files := TStringList.Create;
|
files := TStringList.Create;
|
||||||
try
|
try
|
||||||
@ -1187,6 +1196,9 @@ begin
|
|||||||
ReadXMLFile(doc, AFileName);
|
ReadXMLFile(doc, AFileName);
|
||||||
iconsNode := doc.DocumentElement.FindNode('icons');
|
iconsNode := doc.DocumentElement.FindNode('icons');
|
||||||
iconNode := iconsNode.FindNode('icon');
|
iconNode := iconsNode.FindNode('icon');
|
||||||
|
{$ifdef SPEED_TIMER}
|
||||||
|
t2 := Now();
|
||||||
|
{$endif}
|
||||||
while iconNode <> nil do begin
|
while iconNode <> nil do begin
|
||||||
fn := '';
|
fn := '';
|
||||||
style := isAnystyle;
|
style := isAnystyle;
|
||||||
@ -1223,8 +1235,8 @@ begin
|
|||||||
AddIcon(fn, keywords, style, w, h).Hidden := AHidden;
|
AddIcon(fn, keywords, style, w, h).Hidden := AHidden;
|
||||||
|
|
||||||
// Delete the processed filename from the files list
|
// Delete the processed filename from the files list
|
||||||
i := files.IndexOf(fn);
|
if files.Find(fn, i) then
|
||||||
if i > -1 then files.Delete(i);
|
files.Delete(i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
iconNode := iconNode.NextSibling;
|
iconNode := iconNode.NextSibling;
|
||||||
@ -1254,10 +1266,20 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$ifdef SPEED_TIMER}
|
||||||
|
t2 := Now()-t2;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
finally
|
finally
|
||||||
doc.Free;
|
doc.Free;
|
||||||
files.Free;
|
files.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$ifdef SPEED_TIMER}
|
||||||
|
t1 := Now() - t1;
|
||||||
|
DebugLn(['[TIconThumbnailViewer.ReadMetadataFile] Total time=', FormatDateTime('s.zzz "sec"', t1), ', Loop time=', FormatdateTime('s.zzz "sec"', t2)]);
|
||||||
|
{$endif}
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIconThumbnailViewer.SetFilterByIconKeywords(AValue: String);
|
procedure TIconThumbnailViewer.SetFilterByIconKeywords(AValue: String);
|
||||||
|
@ -293,7 +293,7 @@ var
|
|||||||
Config: TConfigStorage;
|
Config: TConfigStorage;
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
Config := GetIDEConfigStorage(ICONFINDER_CONFIG_FILENAME, true); //, false);
|
Config := GetIDEConfigStorage(ICONFINDER_CONFIG_FILENAME, true);
|
||||||
try
|
try
|
||||||
WriteIconFinderSettings(Config, FViewer, 'IDEOptions');
|
WriteIconFinderSettings(Config, FViewer, 'IDEOptions');
|
||||||
finally
|
finally
|
||||||
|
Loading…
Reference in New Issue
Block a user