UPD #2695: speeding up by macOS property lazy loading on macOS

This commit is contained in:
rich2014 2026-01-10 10:46:30 +08:00
commit c1cfc84933
3 changed files with 28 additions and 13 deletions

View file

@ -257,6 +257,16 @@ end;
{$ELSEIF DEFINED(UNIX)}
{$IFDEF DARWIN}
function PropertyLazyLoader(const path: String; const propertyType: TFilePropertyType): TFileProperty;
begin
if propertyType = fpMacOSSpecific then
Result := TDarwinFilePropertyUtil.getSpecificProperty(path)
else
Result := nil;
end;
{$ENDIF}
procedure FillFromStat(
AFile: TFile;
AFilePath: String;
@ -391,6 +401,7 @@ var
LinkAttrs: TFileAttrs;
begin
Result := TFile.Create(APath);
Result.SetPropertyLazyLoader(@PropertyLazyLoader);
with Result do
begin
@ -429,10 +440,6 @@ begin
end;
{$ENDIF}
end;
{$IFDEF DARWIN}
if pSearchRecord^.Name<>'..' then
MacOSSpecificProperty := TDarwinFilePropertyUtil.getSpecificProperty(AFilePath);
{$ENDIF}
end;
// Set name after assigning Attributes property, because it is used to get extension.
@ -470,6 +477,7 @@ begin
raise EFileNotFound.Create(aFilePath);
Result := TFile.Create(ExtractFilePath(aFilePath));
Result.SetPropertyLazyLoader(@PropertyLazyLoader);
FillFromStat(Result, aFilePath, @StatInfo);
{$ELSE}
@ -488,10 +496,6 @@ begin
{$ENDIF}
{$IFDEF DARWIN}
Result.MacOSSpecificProperty := TDarwinFilePropertyUtil.getSpecificProperty(AFilePath);
{$ENDIF}
// Set name after assigning Attributes property, because it is used to get extension.
Result.FullPath := aFilePath;
end;
@ -762,11 +766,6 @@ begin
CommentProperty.Value := FDescr.ReadDescription(sFullPath);
end;
{$IFDEF DARWIN}
if (AFile.Name<>'..') and (fpMacOSSpecific in PropertiesToSet) then
MacOSSpecificProperty := TDarwinFilePropertyUtil.getSpecificProperty(sFullPath);
{$ENDIF}
PropertiesToSet:= PropertiesToSet * fpVariantAll;
for AProp in PropertiesToSet do
begin

View file

@ -24,6 +24,7 @@ type
FProperties: TFileProperties;
FVariantProperties: TFileVariantProperties;
FSupportedProperties: TFilePropertiesTypes;
FPropertyLazyLoader: TFilePropertyLazyLoader;
procedure UpdateNameAndExtension(const FileName: string);
@ -95,6 +96,8 @@ type
constructor CreateForCloning;
destructor Destroy; override;
procedure SetPropertyLazyLoader( const loader: TFilePropertyLazyLoader );
{en
Creates an identical copy of the object (as far as object data is concerned).
}
@ -330,6 +333,11 @@ begin
FVariantProperties[AIndex].Free;
end;
procedure TFile.SetPropertyLazyLoader(const loader: TFilePropertyLazyLoader);
begin
FPropertyLazyLoader := loader;
end;
function TFile.Clone: TFile;
begin
Result := TFile.CreateForCloning;
@ -347,6 +355,7 @@ begin
AFile.FNameNoExt := FNameNoExt;
AFile.FPath := FPath;
AFile.FSupportedProperties := FSupportedProperties;
AFile.FPropertyLazyLoader:= FPropertyLazyLoader;
for PropertyType := Low(FProperties) to High(FProperties) do
begin
@ -770,6 +779,10 @@ end;
{$IFDEF DARWIN}
function TFile.GetMacOSSpecificProperty: TFileMacOSSpecificProperty;
begin
if FProperties[fpMacOSSpecific] = nil then begin
if FPropertyLazyLoader <> nil then
FProperties[fpMacOSSpecific] := FPropertyLazyLoader(self.FullPath, fpMacOSSpecific);
end;
Result := TFileMacOSSpecificProperty(FProperties[fpMacOSSpecific]);
end;

View file

@ -86,6 +86,9 @@ type
//end
;
// only used by fpMacOSSpecific now
TFilePropertyLazyLoader = function (const path: String; const propertyType: TFilePropertyType): TFileProperty;
// -- Concrete properties ---------------------------------------------------
TFileNameProperty = class(TFileProperty)