diff --git a/src/ce_common.pas b/src/ce_common.pas index 66ddd83a..b6c718c4 100644 --- a/src/ce_common.pas +++ b/src/ce_common.pas @@ -31,7 +31,7 @@ type TCECompiler = (dmd, gdc, ldc); - // function used as hash in gXXX sets & maps + // function used as string hasher in fcl-stl TStringHash = class class function hash(const key: string; maxBucketsPow2: longint): longint; end; @@ -39,12 +39,16 @@ type // HashMap for TValue by string generic TStringHashMap = class(specialize THashmap); - // function used as objects in gXXX sets & maps + // function used as objects haser in fcl-stl TObjectHash = class class function hash(key: TObject; maxBucketsPow2: longint): longint; end; - generic TObjectHashSet = class(specialize THashSet); + // HashSet for any object + generic TObjectHashSet = class(specialize THashSet); + + // Used instead of TStringList when the usage would mostly be ".IndexOf" + TStringHashSet = class(specialize THashSet); // aliased to get a custom prop inspector TCEPathname = type string; @@ -322,7 +326,7 @@ begin {$IFDEF CPU32} Result := longint(Pointer(key)) and (maxBucketsPow2 -1); {$ELSE} - Result := (longInt(Pointer(key)) xor PlongInt(PInteger(&key) + 4)^) and (maxBucketsPow2 -1); + Result := longInt(Pointer(key)){ xor PlongInt(PInteger(&key) + 4)^)} and (maxBucketsPow2 -1); {$ENDIF} {$POP} end; diff --git a/src/ce_dcd.pas b/src/ce_dcd.pas index 52ab400d..027c8a89 100644 --- a/src/ce_dcd.pas +++ b/src/ce_dcd.pas @@ -27,7 +27,7 @@ type private fTempLines: TStringList; fInputSource: string; - fImportCache: TStringList; + fImportCache: TStringHashSet; fPortNum: Word; fServerWasRunning: boolean; fClient, fServer: TProcess; @@ -114,7 +114,7 @@ begin fServer.Parameters.Add('-p' + intToStr(port)); end; fTempLines := TStringList.Create; - fImportCache := TStringList.Create; + fImportCache := TStringHashSet.Create; if fServer.isNotNil then begin @@ -339,8 +339,9 @@ begin if not fAvailable then exit; if not fServerListening then exit; // - if fImportCache.IndexOf(aFolder) <> -1 then exit; - fImportCache.Add(aFolder); + if fImportCache.contains(aFolder) then + exit; + fImportCache.insert(aFolder); fClient.Parameters.Clear; fClient.Parameters.Add('-I' + aFolder); fClient.Execute; @@ -357,9 +358,9 @@ begin fClient.Parameters.Clear; for imp in folders do begin - if fImportCache.IndexOf(imp) <> -1 then + if fImportCache.contains(imp) then continue; - fImportCache.Add(imp); + fImportCache.insert(imp); fClient.Parameters.Add('-I' + imp); end; if fClient.Parameters.Count <> 0 then