Browse Source

* Make dictionary constructor behave as Delphi does in absence of comparer

Michaël Van Canneyt 1 year ago
parent
commit
45cb7d1eff
1 changed files with 5 additions and 1 deletions
  1. 5 1
      packages/rtl-generics/src/inc/generics.dictionaries.inc

+ 5 - 1
packages/rtl-generics/src/inc/generics.dictionaries.inc

@@ -1059,7 +1059,11 @@ constructor TOpenAddressingDH<OPEN_ADDRESSING_CONSTRAINTS>.Create(ACapacity: Siz
   const AComparer: IExtendedEqualityComparer<TKey>);
 begin
   FMaxLoadFactor := TProbeSequence.DEFAULT_LOAD_FACTOR;
-  FEqualityComparer := AComparer;
+  // Delphi creates one if you pass nil...
+  if aComparer=Nil then
+    FEqualityComparer := TExtendedEqualityComparer<TKey>.Default(THashFactory)
+  else
+    FEqualityComparer := AComparer;
   SetCapacity(ACapacity);
 end;