Browse Source

Reducing indirect addressing to out parameters

Alligator-1 7 months ago
parent
commit
886c2ab7d1
1 changed files with 28 additions and 20 deletions
  1. 28 20
      packages/rtl-generics/src/inc/generics.dictionaries.inc

+ 28 - 20
packages/rtl-generics/src/inc/generics.dictionaries.inc

@@ -620,9 +620,12 @@ begin
 end;
 end;
 
 
 function TOpenAddressing<OPEN_ADDRESSING_CONSTRAINTS>.TryGetMutableValue(const AKey: TKey; out APValue: PValue): Boolean;
 function TOpenAddressing<OPEN_ADDRESSING_CONSTRAINTS>.TryGetMutableValue(const AKey: TKey; out APValue: PValue): Boolean;
+var
+  LPValue: PValue;
 begin
 begin
-  APValue := GetMutableValue(AKey);
-  Result := APValue <>Nil;
+  LPValue := GetMutableValue(AKey);
+  APValue := LPValue;
+  Result := LPValue <> Nil;
 end;
 end;
 
 
 function TOpenAddressing<OPEN_ADDRESSING_CONSTRAINTS>.TryGetValue(const AKey: TKey; out AValue: TValue): Boolean;
 function TOpenAddressing<OPEN_ADDRESSING_CONSTRAINTS>.TryGetValue(const AKey: TKey; out AValue: TValue): Boolean;
@@ -805,12 +808,13 @@ begin
   LHash := FEqualityComparer.GetHashCode(AKey);
   LHash := FEqualityComparer.GetHashCode(AKey);
 
 
   i := 0;
   i := 0;
-  AHash := LHash or UInt32.GetSignMask;
+  LHash := LHash or UInt32.GetSignMask;
+  AHash := LHash;
 
 
   if m = 0 then
   if m = 0 then
     Exit(-1);
     Exit(-1);
 
 
-  Result := AHash and LLengthMask;
+  Result := LHash and LLengthMask;
 
 
   repeat
   repeat
     LItem := _TItem(AItems[Result]);
     LItem := _TItem(AItems[Result]);
@@ -820,13 +824,13 @@ begin
       Exit(not Result); // insert!
       Exit(not Result); // insert!
 
 
     // Same position?
     // Same position?
-    if LItem.Hash = AHash then
+    if LItem.Hash = LHash then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
         Exit;
         Exit;
 
 
     Inc(i);
     Inc(i);
 
 
-    Result := TProbeSequence.Probe(i, AHash) and LLengthMask;
+    Result := TProbeSequence.Probe(i, LHash) and LLengthMask;
 
 
   until false;
   until false;
 end;
 end;
@@ -899,12 +903,13 @@ begin
   LHash := FEqualityComparer.GetHashCode(AKey);
   LHash := FEqualityComparer.GetHashCode(AKey);
 
 
   i := 0;
   i := 0;
-  AHash := LHash or UInt32.GetSignMask;
+  LHash := LHash or UInt32.GetSignMask;
+  AHash := LHash;
 
 
   if m = 0 then
   if m = 0 then
     Exit(-1);
     Exit(-1);
 
 
-  Result := AHash and LLengthMask;
+  Result := LHash and LLengthMask;
 
 
   repeat
   repeat
     LItem := _TItem(AItems[Result]);
     LItem := _TItem(AItems[Result]);
@@ -913,13 +918,13 @@ begin
       Exit(not Result); // insert!
       Exit(not Result); // insert!
 
 
     // Same position?
     // Same position?
-    if LItem.Hash = AHash then
+    if LItem.Hash = LHash then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
         Exit;
         Exit;
 
 
     Inc(i);
     Inc(i);
 
 
-    Result := TProbeSequence.Probe(i, AHash) and LLengthMask;
+    Result := TProbeSequence.Probe(i, LHash) and LLengthMask;
 
 
   until false;
   until false;
 end;
 end;
@@ -938,12 +943,13 @@ begin
   LHash := FEqualityComparer.GetHashCode(AKey);
   LHash := FEqualityComparer.GetHashCode(AKey);
 
 
   i := 0;
   i := 0;
-  AHash := LHash or UInt32.GetSignMask;
+  LHash := LHash or UInt32.GetSignMask;
+  AHash := LHash;
 
 
   if m = 0 then
   if m = 0 then
     Exit(-1);
     Exit(-1);
 
 
-  Result := AHash and LLengthMask;
+  Result := LHash and LLengthMask;
 
 
   repeat
   repeat
     LItem := _TItem(AItems[Result]);
     LItem := _TItem(AItems[Result]);
@@ -953,13 +959,13 @@ begin
       Exit(not Result); // insert!
       Exit(not Result); // insert!
 
 
     // Same position?
     // Same position?
-    if LItem.Hash = AHash then
+    if LItem.Hash = LHash then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
         Exit;
         Exit;
 
 
     Inc(i);
     Inc(i);
 
 
-    Result := TProbeSequence.Probe(i, AHash) and LLengthMask;
+    Result := TProbeSequence.Probe(i, LHash) and LLengthMask;
 
 
   until false;
   until false;
 end;
 end;
@@ -989,14 +995,15 @@ begin
   LHash := FEqualityComparer.GetHashCode(AKey);
   LHash := FEqualityComparer.GetHashCode(AKey);
 
 
   i := 0;
   i := 0;
-  AHash := LHash or UInt32.GetSignMask;
+  LHash := LHash or UInt32.GetSignMask;
+  AHash := LHash;
 
 
   if Length(AItems) = 0 then
   if Length(AItems) = 0 then
     Exit(-1);
     Exit(-1);
 
 
   for i := 0 to FPrimaryNumberAsSizeApproximation - 1 do
   for i := 0 to FPrimaryNumberAsSizeApproximation - 1 do
   begin
   begin
-    Result := TProbeSequence.Probe(i, AHash) mod FPrimaryNumberAsSizeApproximation;
+    Result := TProbeSequence.Probe(i, LHash) mod FPrimaryNumberAsSizeApproximation;
     LItem := _TItem(AItems[Result]);
     LItem := _TItem(AItems[Result]);
 
 
     // Empty position
     // Empty position
@@ -1004,7 +1011,7 @@ begin
       Exit(not Result); // insert!
       Exit(not Result); // insert!
 
 
     // Same position?
     // Same position?
-    if LItem.Hash = AHash then
+    if LItem.Hash = LHash then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
         Exit;
         Exit;
   end;
   end;
@@ -1023,14 +1030,15 @@ begin
   LHash := FEqualityComparer.GetHashCode(AKey);
   LHash := FEqualityComparer.GetHashCode(AKey);
 
 
   i := 0;
   i := 0;
-  AHash := LHash or UInt32.GetSignMask;
+  LHash := LHash or UInt32.GetSignMask;
+  AHash := LHash;
 
 
   if Length(AItems) = 0 then
   if Length(AItems) = 0 then
     Exit(-1);
     Exit(-1);
 
 
   for i := 0 to FPrimaryNumberAsSizeApproximation - 1 do
   for i := 0 to FPrimaryNumberAsSizeApproximation - 1 do
   begin
   begin
-    Result := TProbeSequence.Probe(i, AHash) mod FPrimaryNumberAsSizeApproximation;
+    Result := TProbeSequence.Probe(i, LHash) mod FPrimaryNumberAsSizeApproximation;
     LItem := _TItem(AItems[Result]);
     LItem := _TItem(AItems[Result]);
 
 
     // Empty position or tombstone
     // Empty position or tombstone
@@ -1038,7 +1046,7 @@ begin
       Exit(not Result); // insert!
       Exit(not Result); // insert!
 
 
     // Same position?
     // Same position?
-    if LItem.Hash = AHash then
+    if LItem.Hash = LHash then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
       if FEqualityComparer.Equals(AKey, LItem.Pair.Key) then
         Exit;
         Exit;
   end;
   end;