OPM: Faster string comparison.

git-svn-id: trunk@64462 -
This commit is contained in:
juha 2021-02-05 11:28:02 +00:00
parent d6aedf99e8
commit 64656b41e2
11 changed files with 71 additions and 66 deletions

View File

@ -299,7 +299,7 @@ begin
while Assigned(Node) do
begin
Data := FVST.GetNodeData(Node);
if UpperCase(Data^.FName) = UpperCase(AName) then
if CompareText(Data^.FName, AName) = 0 then
begin
FVST.CheckState[Node] := csCheckedNormal;
Result := True;
@ -331,7 +331,7 @@ begin
Data := FVST.GetNodeData(Node);
Data^.FName := Categories[I];
Data^.FImageIndex := -1;
if UpperCase(CategoriesEng[I]) = 'OTHER' then
if CompareText(CategoriesEng[I], 'OTHER') = 0 then
Data^.FType := 1
else
Data^.FType := 0;

View File

@ -33,7 +33,7 @@ uses
// LCL
Dialogs, Forms, Controls,
// LazUtils
LazFileUtils,
LazFileUtils, LazLoggerBase,
// IdeIntf
LazIDEIntf, PackageIntf,
// OpkMan
@ -298,11 +298,11 @@ var
Result := True;
for I := 0 to SLExcludedFolders.Count - 1 do
begin
if UpperCase(SLExcludedFolders.Strings[I]) = UpperCase(AName) then
begin
Result := False;
Break;
end;
if CompareText(SLExcludedFolders.Strings[I], AName) = 0 then
begin
Result := False;
Break;
end;
end;
end;
@ -317,7 +317,7 @@ var
begin
try
repeat
if (UpperCase(ExtractFileExt(SR.Name)) = UpperCase('.lpk')) then
if CompareFileExtQuick(SR.Name, 'lpk') = 0 then
begin
PackageData := TPackageData.Create;
PackageData.FName := SR.Name;
@ -384,7 +384,8 @@ var
begin
for I := 0 to SLExcludedFiles.Count - 1 do
begin
if UpperCase(SLExcludedFiles.Strings[I]) = UpperCase(ExtractFileExt(AName)) then
DebugLn(['OPM IsAllowed: ExcFile=', SLExcludedFiles.Strings[I], ', AName=', AName]);
if CompareFileExt(AName, SLExcludedFiles.Strings[I], False) = 0 then
begin
Result := False;
Break;
@ -394,11 +395,14 @@ var
else
begin
for I := 0 to SLExcludedFolders.Count - 1 do
if UpperCase(SLExcludedFolders.Strings[I]) = UpperCase(AName) then
begin
DebugLn(['OPM IsAllowed: ExcFolder=', SLExcludedFolders.Strings[I], ', AName=', AName]);
if CompareText(SLExcludedFolders.Strings[I], AName) = 0 then
begin
Result := False;
Break;
end;
end;
end;
end;

View File

@ -117,7 +117,7 @@ begin
begin
for I := 0 to PackageEditingInterface.GetPackageCount - 1 do
begin
if UpperCase(PackageEditingInterface.GetPackages(I).Filename) = UpperCase(AFileName) then
if CompareText(PackageEditingInterface.GetPackages(I).Filename, AFileName) = 0 then
begin
Result := PackageEditingInterface.GetPackages(I);
Break;
@ -139,7 +139,7 @@ begin
PkgFileName := Copy(FToInstall.Strings[I], 1, P - 1)
else
PkgFileName := FToInstall.Strings[I];
if UpperCase(PkgFileName) = UpperCase(AFileName) then
if CompareText(PkgFileName, AFileName) = 0 then
begin
Result := True;
Break;
@ -360,8 +360,9 @@ begin
DependecyPackage := SerializablePackages.FindLazarusPackage(PackageDependency.PkgFileName + '.lpk');
if DependecyPackage <> nil then
begin
if UpperCase(DependecyPackage.Name) = UpperCase(TLazarusPackage(FPackageList.Items[I]).Name) then
begin
if CompareText(DependecyPackage.Name,
TLazarusPackage(FPackageList.Items[I]).Name) = 0
then begin
CanGo := False;
SPos := I;
EPos := J;

View File

@ -180,7 +180,7 @@ begin
for I := 0 to FPackageLinks.Count - 1 do
begin
PackageLink := TPackageLink(FPackageLinks.Items[I]);
if UpperCase(PackageLink.Name) = UpperCase(AName) then
if CompareText(PackageLink.Name, AName) = 0 then
begin
Result := PackageLink;
Break;
@ -259,7 +259,7 @@ begin
for J := 0 to MetaPackage.LazarusPackages.Count - 1 do
begin
LazPackage := TLazarusPackage(MetaPackage.LazarusPackages.Items[J]);
if UpperCase(LazPackage.Name) = UpperCase(AName) then
if CompareText(LazPackage.Name, AName) = 0 then
begin
LazPackage.Checked := True;
MetaPackage.Checked := True;
@ -282,7 +282,7 @@ begin
for J := 0 to MetaPackage.LazarusPackages.Count - 1 do
begin
LazPackage := TLazarusPackage(MetaPackage.LazarusPackages.Items[J]);
if UpperCase(LazPackage.Name) = UpperCase(AName) then
if CompareText(LazPackage.Name, AName) = 0 then
begin
FPackagesToInstall.Add(LazPackage);
Break;
@ -295,32 +295,35 @@ function TOPMInterfaceEx.ResolveDependencies: TModalResult;
var
I, J: Integer;
PackageList: TObjectList;
PkgFileName: String;
Msg, LazPkgName, PkgFileName: String;
DependencyPkg: TLazarusPackage;
MetaPkg: TMetaPackage;
Msg: String;
begin
Result := mrNone;
FPackageDependecies.Clear;
for I := 0 to FPackagesToInstall.Count - 1 do
begin
LazPkgName := TLazarusPackage(FPackagesToInstall.Items[I]).Name;
PackageList := TObjectList.Create(True);
try
SerializablePackages.GetPackageDependencies(TLazarusPackage(FPackagesToInstall.Items[I]).Name, PackageList, True, True);
SerializablePackages.GetPackageDependencies(LazPkgName, PackageList, True, True);
for J := 0 to PackageList.Count - 1 do
begin
PkgFileName := TPackageDependency(PackageList.Items[J]).PkgFileName + '.lpk';
DependencyPkg := SerializablePackages.FindLazarusPackage(PkgFileName);
if DependencyPkg <> nil then
begin
if (not DependencyPkg.Checked) and
(UpperCase(TLazarusPackage(FPackagesToInstall.Items[I]).Name) <> UpperCase(PkgFileName)) and
((SerializablePackages.IsDependencyOk(TPackageDependency(PackageList.Items[J]), DependencyPkg)) and
((not (DependencyPkg.PackageState = psInstalled)) or ((DependencyPkg.PackageState = psInstalled) and (not (SerializablePackages.IsInstalledVersionOk(TPackageDependency(PackageList.Items[J]), DependencyPkg.InstalledFileVersion)))))) then
if (not DependencyPkg.Checked) and (CompareText(LazPkgName, PkgFileName) <> 0)
and ((SerializablePackages.IsDependencyOk(TPackageDependency(PackageList.Items[J]), DependencyPkg))
and
((not (DependencyPkg.PackageState = psInstalled))
or ((DependencyPkg.PackageState = psInstalled)
and (not (SerializablePackages.IsInstalledVersionOk(
TPackageDependency(PackageList.Items[J]), DependencyPkg.InstalledFileVersion)))))) then
begin
if (Result = mrNone) or (Result = mrYes) then
begin
Msg := Format(rsMainFrm_rsPackageDependency0, [TLazarusPackage(FPackagesToInstall.Items[I]).Name, DependencyPkg.Name]);
Msg := Format(rsMainFrm_rsPackageDependency0, [LazPkgName, DependencyPkg.Name]);
Result := MessageDlgEx(Msg, mtConfirmation, [mbYes, mbYesToAll, mbNo, mbNoToAll, mbCancel], nil);
if Result in [mrNo, mrNoToAll] then
if MessageDlgEx(rsMainFrm_rsPackageDependency1, mtInformation, [mbYes, mbNo], nil) <> mrYes then

View File

@ -356,7 +356,7 @@ begin
while Assigned(Node) do
begin
Data := FVST.GetNodeData(Node);
if UpperCase(Data^.LazarusPackageName + '.lpk') = UpperCase(AName) then
if CompareText(Data^.LazarusPackageName + '.lpk', AName) = 0 then
begin
Result := Node^.CheckState = csCheckedNormal;
Break;

View File

@ -893,7 +893,7 @@ procedure TMainFrm.tbUninstallClick(Sender: TObject);
for I := 0 to PackageEditingInterface.GetPackageCount - 1 do
begin
IDEPackge := PackageEditingInterface.GetPackages(I);
if UpperCase(IDEPackge.Filename) = UpperCase(AFileName) then
if CompareText(IDEPackge.Filename, AFileName) = 0 then
begin
Result := IDEPackge;
Break;
@ -1290,10 +1290,10 @@ end;
procedure TMainFrm.miLoadClick(Sender: TObject);
var
SL: TStringList;
I: Integer;
TrimmedS: String;
I, CheckCount: Integer;
Node: PVirtualNode;
Data: PData;
CheckCount: Integer;
begin
if OD.Execute then
begin
@ -1303,11 +1303,12 @@ begin
SL.LoadFromFile(OD.FileName);
for I := 0 to SL.Count - 1 do
begin
TrimmedS := Trim(SL.Strings[I]);
Node := VisualTree.VST.GetFirst;
while Node <> nil do
begin
Data := VisualTree.VST.GetNodeData(Node);
if UpperCase(Trim(Data^.LazarusPackageName)) = UpperCase(Trim(SL.Strings[I])) then
if CompareText(Trim(Data^.LazarusPackageName), TrimmedS) = 0 then
begin
VisualTree.VST.CheckState[Node] := csCheckedNormal;
Inc(CheckCount);

View File

@ -366,7 +366,7 @@ begin
while Assigned(Node) do
begin
Data := FVST.GetNodeData(Node);
if (UpperCase(Data^.FAddress) = UpperCase(AAddress)) and (Data^.FUniqueID <> AUniqueID) then
if (CompareText(Data^.FAddress, AAddress) = 0) and (Data^.FUniqueID <> AUniqueID) then
begin
Result := True;
Break;

View File

@ -69,7 +69,7 @@ begin
Result := False;
for I := 0 to Options.RemoteRepository.Count - 1 do
begin
if UpperCase(Options.RemoteRepository.Strings[I]) = UpperCase(AAddress) then
if CompareText(Options.RemoteRepository.Strings[I], AAddress) = 0 then
begin
Result := True;
Break;

View File

@ -586,7 +586,7 @@ begin
for I := 0 to FLazarusPackages.Count - 1 do
begin
Result := TLazarusPackage(FLazarusPackages.Items[I]);
if UpperCase(Result.Name) = UpperCase(APackageName) then
if CompareText(Result.Name, APackageName) = 0 then
Exit;
end;
Result := nil;
@ -770,20 +770,17 @@ function TSerializablePackages.FindMetaPackage(const AValue: String;
const AFindPackageBy: TFindPackageBy): TMetaPackage;
var
I: Integer;
NeedToBreak: Boolean;
S: String;
begin
Result := nil;
for I := 0 to Count - 1 do
begin
case AFindPackageBy of
fpbPackageName: NeedToBreak := UpperCase(Items[I].Name) = UpperCase(AValue);
fpbRepositoryFilename: NeedToBreak := UpperCase(Items[I].RepositoryFileName) = UpperCase(AValue)
end;
if NeedToBreak then
begin
Result := Items[I];
Break;
fpbPackageName: S := Items[I].Name;
fpbRepositoryFilename: S := Items[I].RepositoryFileName;
end;
if CompareText(S, AValue) = 0 then
Exit(Items[I]);
end;
end;
@ -810,24 +807,20 @@ function TSerializablePackages.FindPackageIndex(const AValue: String;
const AFindPackageBy: TFindPackageBy): Integer;
var
I: Integer;
NeedToBreak: Boolean;
S: String;
begin
Result := -1;
for I := 0 to Count - 1 do
begin
case AFindPackageBy of
fpbPackageName: NeedToBreak := Items[I].Name = AValue;
fpbRepositoryFilename: NeedToBreak := Items[I].RepositoryFileName = AValue
end;
if NeedToBreak then
begin
Result := I;
Break;
fpbPackageName: S := Items[I].Name;
fpbRepositoryFilename: S := Items[I].RepositoryFileName;
end;
if S = AValue then
Exit(I);
end;
end;
function TSerializablePackages.FindLazarusPackage(const APackageName: String): TLazarusPackage;
var
I, J: Integer;
@ -837,7 +830,7 @@ begin
begin
for J := 0 to Items[I].FLazarusPackages.Count - 1 do
begin
if UpperCase(TLazarusPackage(Items[I].FLazarusPackages.Items[J]).Name) = UpperCase(APackageName) then
if CompareText(TLazarusPackage(Items[I].FLazarusPackages.Items[J]).Name, APackageName) = 0 then
begin
Result := TLazarusPackage(Items[I].FLazarusPackages.Items[J]);
Break;
@ -1399,7 +1392,7 @@ begin
for J := 0 to PackageEditingInterface.GetPackageCount - 1 do
begin
IDEPackage := PackageEditingInterface.GetPackages(J);
if UpperCase(ExtractFileName(IDEPackage.Filename)) = UpperCase(PackageName) then
if CompareText(ExtractFileName(IDEPackage.Filename), PackageName) = 0 then
begin
LazarusPkg := FindLazarusPackage(PackageName);
if LazarusPkg <> nil then

View File

@ -1365,7 +1365,7 @@ begin
begin
DependencyPkg := TLazarusPackage(SerializablePackages.Items[DataSearch^.PID].LazarusPackages.Items[DataSearch^.PFID]);
if (FVST.CheckState[NodeSearch] <> csCheckedNormal) and
(UpperCase(DataSearch^.LazarusPackageName) = UpperCase(PkgFileName)) and
(CompareText(DataSearch^.LazarusPackageName, PkgFileName) = 0) and
((SerializablePackages.IsDependencyOk(TPackageDependency(PackageList.Items[I]), DependencyPkg)) and
((not (DependencyPkg.PackageState = psInstalled)) or ((DependencyPkg.PackageState = psInstalled) and (not (SerializablePackages.IsInstalledVersionOk(TPackageDependency(PackageList.Items[I]), DataSearch^.InstalledVersion)))))) then
begin

View File

@ -142,38 +142,41 @@ procedure TPackageUnzipper.Execute;
var
I: Integer;
DelDir: String;
MPkg: TMetaPackage;
begin
Sleep(50);
FCnt := 0;
FStartTime := GetTickCount64;
for I := 0 to SerializablePackages.Count - 1 do
begin
if SerializablePackages.Items[I].IsExtractable then
MPkg := SerializablePackages.Items[I];
if MPkg.IsExtractable then
begin
if FNeedToBreak then
Break;
Inc(FCnt);
FCurPos := 0;
FZipFile := SerializablePackages.Items[I].RepositoryFileName;
DelDir := FDstDir + SerializablePackages.Items[I].PackageBaseDir;
FZipFile := MPkg.RepositoryFileName;
DelDir := FDstDir + MPkg.PackageBaseDir;
if FIsUpdate then
if DirectoryExists(DelDir) then
DeleteDirectory(DelDir, False);
try
FUnZipper.Clear;
FUnZipper.FileName := FSrcDir + SerializablePackages.Items[I].RepositoryFileName;
if SerializablePackages.Items[I].IsDirZipped then
FUnZipper.FileName := FSrcDir + MPkg.RepositoryFileName;
if MPkg.IsDirZipped then
FUnZipper.OutputPath := FDstDir
else
FUnZipper.OutputPath := FDstDir + SerializablePackages.Items[I].PackageBaseDir;
FUnZipper.OutputPath := FDstDir + MPkg.PackageBaseDir;
FUnZipper.OnProgressEx := @DoOnProgressEx;
FUnZipper.Examine;
FUnZipper.UnZipAllFiles;
SerializablePackages.Items[I].ChangePackageStates(ctAdd, psExtracted);
if (SerializablePackages.Items[I].IsDirZipped ) and (UpperCase(SerializablePackages.Items[I].PackageBaseDir) <> UpperCase(SerializablePackages.Items[I].ZippedBaseDir)) then
MPkg.ChangePackageStates(ctAdd, psExtracted);
if (MPkg.IsDirZipped )
and (CompareText(MPkg.PackageBaseDir, MPkg.ZippedBaseDir) <> 0) then
begin
CopyDirTree(FUnZipper.OutputPath + SerializablePackages.Items[I].ZippedBaseDir, DelDir, [cffOverwriteFile]);
DeleteDirectory(FUnZipper.OutputPath + SerializablePackages.Items[I].ZippedBaseDir, False);
CopyDirTree(FUnZipper.OutputPath + MPkg.ZippedBaseDir, DelDir, [cffOverwriteFile]);
DeleteDirectory(FUnZipper.OutputPath + MPkg.ZippedBaseDir, False);
end;
Synchronize(@DoOnZipProgress);
FTotPos := FTotPos + FCurSize;
@ -181,8 +184,8 @@ begin
on E: Exception do
begin
FErrMsg := E.Message;
SerializablePackages.Items[I].ChangePackageStates(ctRemove, psExtracted);
SerializablePackages.Items[I].ChangePackageStates(ctAdd, psError);
MPkg.ChangePackageStates(ctRemove, psExtracted);
MPkg.ChangePackageStates(ctAdd, psError);
DeleteDirectory(DelDir, False);
Synchronize(@DoOnZipError);
end;