dcd integration, cache imports in a hashset

This commit is contained in:
Basile Burg 2016-07-04 08:31:50 +02:00
parent 7aae871188
commit d92390471d
2 changed files with 15 additions and 10 deletions

View File

@ -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<TValue> = class(specialize THashmap<string, TValue, TStringHash>);
// 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<TValue> = class(specialize THashSet<TValue, TObjectHash>);
// HashSet for any object
generic TObjectHashSet<TValue: TObject> = class(specialize THashSet<TValue, TObjectHash>);
// Used instead of TStringList when the usage would mostly be ".IndexOf"
TStringHashSet = class(specialize THashSet<string, TStringHash>);
// 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;

View File

@ -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