Skip to content

Commit 9c0c934

Browse files
committed
removed unnecessary constructor overloads
1 parent 9a1fc4a commit 9c0c934

11 files changed

+96
-205
lines changed

Source/Base/Collections/Spring.Collections.Base.pas

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ TEnumerableBase<T> = class abstract(TEnumerableBase)
7272
function UseComparer(typeKind: TTypeKind): Boolean; inline;
7373
property Comparer: IComparer<T> read fComparer;
7474
public
75-
constructor Create; overload; virtual;
76-
constructor Create(const comparer: IComparer<T>); overload;
77-
constructor Create(const comparer: TComparison<T>); overload;
75+
constructor Create;
7876

7977
function Aggregate(const func: Func<T, T, T>): T;
8078

@@ -349,7 +347,7 @@ TIterator<T> = class abstract(TEnumerableBase<T>, IEnumerator<T>)
349347
procedure Start; virtual;
350348
function TryMoveNext(var current: T): Boolean; virtual; abstract;
351349
public
352-
constructor Create; override;
350+
constructor Create;
353351
function GetEnumerator: IEnumerator<T>;
354352
function MoveNext: Boolean;
355353
end;
@@ -392,7 +390,7 @@ TCollectionBase<T> = class abstract(TEnumerableBase<T>)
392390
property OnChanged: TCollectionChangedEventImpl<T> read fOnChanged;
393391
property Notify: TNotify read fNotify;
394392
public
395-
constructor Create; override;
393+
constructor Create;
396394
destructor Destroy; override;
397395

398396
procedure AddRange(const values: array of T); overload;
@@ -527,9 +525,7 @@ TEnumerator = class(TRefCountedObject, IEnumerator<T>)
527525
property Tail: PT read GetTail;
528526
property OwnsObjects: Boolean read GetOwnsObjects;
529527
public
530-
constructor Create; override;
531-
constructor Create(capacity: Integer; ownsObjects: Boolean = False); overload;
532-
constructor Create(ownsObjects: Boolean); overload;
528+
constructor Create(capacity: Integer = 0; ownsObjects: Boolean = False);
533529
destructor Destroy; override;
534530

535531
{$REGION 'Implements IEnumerable<T>'}
@@ -564,7 +560,7 @@ TMapBase<TKey, T> = class abstract(TCollectionBase<TPair<TKey, T>>)
564560
procedure KeyChanged(const item: TKey; action: TCollectionChangedAction); inline;
565561
procedure ValueChanged(const item: T; action: TCollectionChangedAction); inline;
566562
public
567-
constructor Create; override;
563+
constructor Create;
568564
destructor Destroy; override;
569565

570566
function Add(const item: TKeyValuePair): Boolean; overload;
@@ -839,18 +835,6 @@ constructor TEnumerableBase<T>.Create;
839835
fComparer := IComparer<T>(_LookupVtableInfo(giComparer, GetElementType, SizeOf(T)));
840836
end;
841837

842-
constructor TEnumerableBase<T>.Create(const comparer: IComparer<T>);
843-
begin
844-
Create;
845-
if Assigned(comparer) then
846-
fComparer := comparer;
847-
end;
848-
849-
constructor TEnumerableBase<T>.Create(const comparer: TComparison<T>);
850-
begin
851-
Create(IComparer<T>(PPointer(@comparer)^));
852-
end;
853-
854838
function TEnumerableBase<T>.UseComparer(typeKind: TTypeKind): Boolean;
855839
const
856840
FastComparableTypes = [tkUnknown, tkInteger, tkChar, tkEnumeration, tkSet,
@@ -1813,8 +1797,9 @@ procedure TIterator<T>.Start;
18131797

18141798
constructor TSourceIterator<T>.Create(const source: IEnumerable<T>);
18151799
begin
1800+
fComparer := source.Comparer;
18161801
fSource := source;
1817-
inherited Create(fSource.Comparer);
1802+
inherited Create;
18181803
end;
18191804

18201805
function TSourceIterator<T>.GetElementType: PTypeInfo;
@@ -2057,10 +2042,10 @@ constructor TInnerCollection<T>.Create(const source: TRefCountedObject;
20572042
hashTable: PHashTable; elementType: PTypeInfo;
20582043
const comparer: IEqualityComparer<T>; offset: Integer);
20592044
begin
2060-
inherited Create(IComparer<T>(_LookupVtableInfo(giComparer, elementType, SizeOf(T))));
2045+
fElementType := elementType;
2046+
inherited Create;
20612047
fSource := source;
20622048
fHashTable := hashTable;
2063-
fElementType := elementType;
20642049
fComparer := comparer;
20652050
fOffset := THashTable.KeyOffset + offset;
20662051
end;
@@ -2240,25 +2225,14 @@ function THashTableEnumerator.MoveNext: Boolean;
22402225

22412226
{$REGION 'TCircularArrayBuffer<T>'}
22422227

2243-
constructor TCircularArrayBuffer<T>.Create;
2228+
constructor TCircularArrayBuffer<T>.Create(capacity: Integer; ownsObjects: Boolean);
22442229
begin
22452230
inherited Create;
22462231
fOnChanged := TCollectionChangedEventImpl<T>.Create;
2247-
end;
2248-
2249-
constructor TCircularArrayBuffer<T>.Create(capacity: Integer; ownsObjects: Boolean);
2250-
begin
2251-
Create;
22522232
SetCapacity(capacity);
22532233
SetOwnsObjects(ownsObjects);
22542234
end;
22552235

2256-
constructor TCircularArrayBuffer<T>.Create(ownsObjects: Boolean);
2257-
begin
2258-
Create;
2259-
SetOwnsObjects(ownsObjects);
2260-
end;
2261-
22622236
destructor TCircularArrayBuffer<T>.Destroy;
22632237
begin
22642238
Clear;
@@ -2823,7 +2797,8 @@ constructor TIteratorBase<T>.Create(const source: IEnumerable<T>;
28232797
StartFuncs: array[TIteratorKind] of Pointer;
28242798
begin
28252799
fIterator.Source := source;
2826-
inherited Create(source.Comparer);
2800+
fComparer := source.Comparer;
2801+
inherited Create;
28272802
fIterator.TypeInfo := TypeInfo(TIteratorRec<T>);
28282803
fIterator.Count := count;
28292804
fIterator.Predicate := IInterface(predicate);

Source/Base/Collections/Spring.Collections.Dictionaries.pas

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ TEnumerator = class(THashTableEnumerator, IEnumerator<TKeyValuePair>)
100100
const keyComparer: IEqualityComparer<TKey>;
101101
const valueComparer: IEqualityComparer<TValue>;
102102
ownerships: TDictionaryOwnerships);
103-
104103
destructor Destroy; override;
105104

106105
{$REGION 'Implements IEnumerable<TPair<TKey, TValue>>'}
@@ -507,8 +506,8 @@ TValueCollection = class(TEnumerableBase<TValue>,
507506
function DoMoveNext(var currentNode: PNode; var finished: Boolean;
508507
iteratorVersion: Integer): Boolean;
509508
public
510-
constructor Create; override;
511-
constructor Create(const keyComparer: IComparer<TKey>; const valueComparer: IEqualityComparer<TValue>); overload;
509+
constructor Create(const keyComparer: IComparer<TKey>;
510+
const valueComparer: IEqualityComparer<TValue>);
512511
destructor Destroy; override;
513512

514513
{$REGION 'Implements IEnumerable<TPair<TKey, TValue>>'}
@@ -615,8 +614,8 @@ constructor TDictionary<TKey, TValue>.Create(capacity: Integer;
615614
if ValueType.Kind <> tkClass then
616615
raise Error.NoClassType(ValueType);
617616

618-
inherited Create();
619617
fComparer := TComparer.Create(nil);
618+
inherited Create;
620619
fOwnerships := ownerships;
621620
if Assigned(keyComparer) then
622621
fKeyComparer := keyComparer
@@ -2305,15 +2304,11 @@ function TBidiDictionary<TKey, TValue>.TValueCollection._Release: Integer;
23052304

23062305
{$REGION 'TSortedDictionary<TKey, TValue>'}
23072306

2308-
constructor TSortedDictionary<TKey, TValue>.Create;
2309-
begin
2310-
Create(nil, nil);
2311-
end;
2312-
23132307
constructor TSortedDictionary<TKey, TValue>.Create(
23142308
const keyComparer: IComparer<TKey>;
23152309
const valueComparer: IEqualityComparer<TValue>);
23162310
begin
2311+
fComparer := TComparer.Create(nil);
23172312
inherited Create;
23182313

23192314
fKeys := TKeyCollection.Create(Self);
@@ -2324,7 +2319,6 @@ constructor TSortedDictionary<TKey, TValue>.Create(
23242319
fKeyComparer := keyComparer
23252320
else
23262321
fKeyComparer := IComparer<TKey>(_LookupVtableInfo(giComparer, TypeInfo(TKey), SizeOf(TKey)));
2327-
fComparer := TComparer.Create(nil);
23282322
if Assigned(valueComparer) then
23292323
fValueComparer := valueComparer
23302324
else

Source/Base/Collections/Spring.Collections.Lists.pas

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ TEnumerator = class(TRefCountedObject, IEnumerator<T>)
107107
property Items[index: Integer]: T read GetItem write SetItem; default;
108108
property OwnsObjects: Boolean read GetOwnsObjects;
109109
public
110-
constructor Create(const values: array of T); overload;
111-
constructor Create(const values: IEnumerable<T>); overload;
110+
constructor Create(const comparer: IComparer<T>); overload;
112111
destructor Destroy; override;
113112

114113
{$REGION 'Implements IEnumerable<T>'}
@@ -381,37 +380,10 @@ implementation
381380

382381
{$REGION 'TAbstractArrayList<T>'}
383382

384-
constructor TAbstractArrayList<T>.Create(const values: array of T);
385-
var
386-
count, i: Integer;
383+
constructor TAbstractArrayList<T>.Create(const comparer: IComparer<T>);
387384
begin
388-
Create;
389-
count := Length(values);
390-
if count > 0 then
391-
begin
392-
SetCount(count);
393-
for i := Low(values) to High(values) do
394-
fItems[i] := values[i];
395-
end;
396-
end;
397-
398-
constructor TAbstractArrayList<T>.Create(const values: IEnumerable<T>);
399-
var
400-
collection: IReadOnlyCollection<T>;
401-
count: Integer;
402-
begin
403-
Create;
404-
if Supports(values, IReadOnlyCollection<T>, collection) then
405-
begin
406-
count := collection.Count;
407-
if count > 0 then
408-
begin
409-
SetCount(count);
410-
collection.CopyTo(fItems, 0);
411-
end;
412-
end
413-
else
414-
AddRange(values);
385+
fComparer := comparer;
386+
inherited Create;
415387
end;
416388

417389
destructor TAbstractArrayList<T>.Destroy;
@@ -462,10 +434,7 @@ procedure TAbstractArrayList<T>.AddRange(const values: IEnumerable<T>);
462434

463435
function TAbstractArrayList<T>.GetEnumerator: IEnumerator<T>;
464436
begin
465-
if TType.Kind<T> = tkClass then
466-
IEnumerator<TObject>(Result) := TList<TObject>.TEnumerator.Create(TList<TObject>(Self))
467-
else
468-
Result := TEnumerator.Create(Self);
437+
Result := TEnumerator.Create(Self);
469438
end;
470439

471440
function TAbstractArrayList<T>.GetIsEmpty: Boolean;
@@ -2020,7 +1989,8 @@ constructor TFoldedSortedList<T>.Create(elementType: PTypeInfo;
20201989
const comparer: IComparer<T>; ownsObjects: Boolean);
20211990
begin
20221991
fElementType := elementType;
2023-
inherited Create(comparer);
1992+
fComparer := comparer;
1993+
inherited Create;
20241994
SetOwnsObjects(ownsObjects);
20251995
end;
20261996

Source/Base/Collections/Spring.Collections.MultiSets.pas

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ TEntryEnumerator = class(TRefCountedObject, IEnumerator<TEntry>)
145145
protected
146146
function CreateMultiSet: IMultiSet<T>; override;
147147
public
148-
constructor Create; override;
149-
constructor Create(const comparer: IEqualityComparer<T>); overload;
148+
constructor Create(const comparer: IEqualityComparer<T>);
150149
destructor Destroy; override;
151150

152151
{$REGION 'Implements IEnumerable<T>'}
@@ -283,8 +282,7 @@ TEntryEnumerator = class(TRefCountedObject, IEnumerator<TEntry>)
283282
protected
284283
function CreateMultiSet: IMultiSet<T>; override;
285284
public
286-
constructor Create; override;
287-
constructor Create(const comparer: IComparer<T>); overload;
285+
constructor Create(const comparer: IComparer<T>);
288286
destructor Destroy; override;
289287

290288
{$REGION 'Implements IEnumerable<T>'}
@@ -351,7 +349,7 @@ function TAbstractMultiSet<T>.OrderedByCount: IReadOnlyMultiSet<T>;
351349
else
352350
Result := 1;
353351
end);
354-
localSet := THashMultiSet<T>.Create;
352+
localSet := THashMultiSet<T>.Create(nil);
355353
for i := 0 to High(items) do
356354
localSet.Add(items[i].Value.Item, items[i].Value.Count);
357355
Result := localSet as IReadOnlyMultiSet<T>;
@@ -382,11 +380,6 @@ function TAbstractMultiSet<T>.SetEquals(const other: IEnumerable<T>): Boolean;
382380

383381
{$REGION 'THashMultiSet<T>'}
384382

385-
constructor THashMultiSet<T>.Create;
386-
begin
387-
Create(nil);
388-
end;
389-
390383
constructor THashMultiSet<T>.Create(const comparer: IEqualityComparer<T>);
391384
begin
392385
inherited Create;
@@ -785,11 +778,6 @@ function THashMultiSet<T>.TEntryEnumerator.MoveNext: Boolean;
785778

786779
{$REGION 'TTreeMultiSet<T>'}
787780

788-
constructor TTreeMultiSet<T>.Create;
789-
begin
790-
Create(nil);
791-
end;
792-
793781
constructor TTreeMultiSet<T>.Create(const comparer: IComparer<T>);
794782
begin
795783
inherited Create;

Source/Base/Collections/Spring.Collections.Queues.pas

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,9 @@ constructor TQueue<T>.Create(const values: array of T);
252252
var
253253
i: Integer;
254254
begin
255-
inherited Create;
256-
SetCapacity(Length(values));
255+
inherited Create(Length(values));
257256
for i := 0 to High(values) do
258-
AddToTail(values[i]);
257+
Enqueue(values[i]);
259258
end;
260259

261260
constructor TQueue<T>.Create(const values: IEnumerable<T>);
@@ -432,18 +431,18 @@ constructor TDeque<T>.Create(const values: array of T);
432431
var
433432
i: Integer;
434433
begin
435-
Create;
434+
inherited Create;
436435
SetCapacity(Length(values));
437-
for i := Low(values) to High(values) do
438-
AddToTail(values[i]);
436+
for i := 0 to High(values) do
437+
AddLast(values[i]);
439438
end;
440439

441440
constructor TDeque<T>.Create(const values: IEnumerable<T>);
442441
var
443442
enumerator: IEnumerator<T>;
444443
item: T;
445444
begin
446-
Create;
445+
inherited Create;
447446
enumerator := values.GetEnumerator;
448447
while enumerator.MoveNext do
449448
begin
@@ -523,8 +522,9 @@ function TEvictingDeque<T>.AddLast(const item: T): Boolean;
523522
constructor TFoldedQueue<T>.Create(const elementType: PTypeInfo;
524523
const comparer: IComparer<T>; ownsObjects: Boolean);
525524
begin
526-
inherited Create(comparer);
527525
fElementType := elementType;
526+
fComparer := comparer;
527+
inherited Create;
528528
SetOwnsObjects(ownsObjects);
529529
end;
530530

0 commit comments

Comments
 (0)