Skip to content

Commit 3fb8327

Browse files
committed
optimized code via compiletime evaluated expressions
1 parent c65e117 commit 3fb8327

File tree

5 files changed

+109
-2
lines changed

5 files changed

+109
-2
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,11 +2536,21 @@ function TCircularArrayBuffer<T>.GetCapacity: Integer;
25362536

25372537
function TCircularArrayBuffer<T>.GetCount: Integer;
25382538
begin
2539+
{$IFDEF DELPHIXE7_UP}
2540+
if GetTypeKind(T) <> tkClass then
2541+
Result := fCount
2542+
else
2543+
{$ENDIF}
25392544
Result := fCount and CountMask;
25402545
end;
25412546

25422547
function TCircularArrayBuffer<T>.GetCountFast: Integer;
25432548
begin
2549+
{$IFDEF DELPHIXE7_UP}
2550+
if GetTypeKind(T) <> tkClass then
2551+
Result := fCount
2552+
else
2553+
{$ENDIF}
25442554
Result := fCount and CountMask;
25452555
end;
25462556

@@ -2798,7 +2808,12 @@ procedure TCircularArrayBuffer<T>.SetCapacity(value: Integer);
27982808

27992809
procedure TCircularArrayBuffer<T>.SetOwnsObjects(value: Boolean);
28002810
begin
2801-
fCount := (fCount and CountMask) or (Ord(value) shl OwnsObjectsBitIndex);
2811+
{$IFDEF DELPHIXE7_UP}
2812+
if GetTypeKind(T) = tkClass then
2813+
{$ELSE}
2814+
if TType.Kind<T> = tkClass then
2815+
{$ENDIF}
2816+
fCount := (fCount and CountMask) or (Ord(value) shl OwnsObjectsBitIndex);
28022817
end;
28032818

28042819
{$ENDREGION}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,19 @@ constructor TDictionary<TKey, TValue>.Create(capacity: Integer;
605605
begin
606606
if capacity < 0 then RaiseHelper.ArgumentOutOfRange(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
607607

608+
{$IFDEF DELPHIXE7_UP}
609+
if GetTypeKind(TKey) <> tkClass then
610+
{$ELSE}
608611
if TType.Kind<TKey> <> tkClass then
612+
{$ENDIF}
609613
if doOwnsKeys in ownerships then
610614
RaiseHelper.NoClassType(TypeInfo(TKey));
611615

616+
{$IFDEF DELPHIXE7_UP}
617+
if GetTypeKind(TValue) <> tkClass then
618+
{$ELSE}
612619
if TType.Kind<TValue> <> tkClass then
620+
{$ENDIF}
613621
if doOwnsValues in ownerships then
614622
RaiseHelper.NoClassType(TypeInfo(TValue));
615623

@@ -1113,11 +1121,19 @@ constructor TBidiDictionary<TKey, TValue>.Create(capacity: Integer;
11131121
begin
11141122
if capacity < 0 then RaiseHelper.ArgumentOutOfRange(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
11151123

1124+
{$IFDEF DELPHIXE7_UP}
1125+
if GetTypeKind(TKey) <> tkClass then
1126+
{$ELSE}
11161127
if TType.Kind<TKey> <> tkClass then
1128+
{$ENDIF}
11171129
if doOwnsKeys in ownerships then
11181130
RaiseHelper.NoClassType(TypeInfo(TKey));
11191131

1132+
{$IFDEF DELPHIXE7_UP}
1133+
if GetTypeKind(TValue) <> tkClass then
1134+
{$ELSE}
11201135
if TType.Kind<TValue> <> tkClass then
1136+
{$ENDIF}
11211137
if doOwnsValues in ownerships then
11221138
RaiseHelper.NoClassType(TypeInfo(TValue));
11231139

@@ -2931,11 +2947,19 @@ constructor TFoldedDictionary<TKey, TValue>.Create(keyType,
29312947
begin
29322948
if capacity < 0 then RaiseHelper.ArgumentOutOfRange(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
29332949

2950+
{$IFDEF DELPHIXE7_UP}
2951+
if GetTypeKind(TKey) <> tkClass then
2952+
{$ELSE}
29342953
if TType.Kind<TKey> <> tkClass then
2954+
{$ENDIF}
29352955
if doOwnsKeys in ownerships then
29362956
RaiseHelper.NoClassType(keyType);
29372957

2958+
{$IFDEF DELPHIXE7_UP}
2959+
if GetTypeKind(TValue) <> tkClass then
2960+
{$ELSE}
29382961
if TType.Kind<TValue> <> tkClass then
2962+
{$ENDIF}
29392963
if doOwnsValues in ownerships then
29402964
RaiseHelper.NoClassType(valueType);
29412965

@@ -2979,11 +3003,19 @@ constructor TFoldedBidiDictionary<TKey, TValue>.Create(keyType, valueType,
29793003
begin
29803004
if capacity < 0 then RaiseHelper.ArgumentOutOfRange(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
29813005

3006+
{$IFDEF DELPHIXE7_UP}
3007+
if GetTypeKind(TKey) <> tkClass then
3008+
{$ELSE}
29823009
if TType.Kind<TKey> <> tkClass then
3010+
{$ENDIF}
29833011
if doOwnsKeys in ownerships then
29843012
RaiseHelper.NoClassType(keyType);
29853013

3014+
{$IFDEF DELPHIXE7_UP}
3015+
if GetTypeKind(TValue) <> tkClass then
3016+
{$ELSE}
29863017
if TType.Kind<TValue> <> tkClass then
3018+
{$ENDIF}
29873019
if doOwnsValues in ownerships then
29883020
RaiseHelper.NoClassType(valueType);
29893021

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,21 @@ function TAbstractArrayList<T>.GetCapacity: Integer;
462462

463463
function TAbstractArrayList<T>.GetCount: Integer;
464464
begin
465+
{$IFDEF DELPHIXE7_UP}
466+
if GetTypeKind(T) <> tkClass then
467+
Result := fCount
468+
else
469+
{$ENDIF}
465470
Result := fCount and CountMask;
466471
end;
467472

468473
function TAbstractArrayList<T>.GetCountFast: Integer;
469474
begin
475+
{$IFDEF DELPHIXE7_UP}
476+
if GetTypeKind(T) <> tkClass then
477+
Result := fCount
478+
else
479+
{$ENDIF}
470480
Result := fCount and CountMask;
471481
end;
472482

@@ -685,7 +695,11 @@ procedure TAbstractArrayList<T>.SetItemInternal(index: Integer; const value: T);
685695

686696
procedure TAbstractArrayList<T>.SetOwnsObjects(value: Boolean);
687697
begin
698+
{$IFDEF DELPHIXE7_UP}
699+
if GetTypeKind(T) = tkClass then
700+
{$ELSE}
688701
if TType.Kind<T> = tkClass then
702+
{$ENDIF}
689703
fCount := (fCount and CountMask) or (Ord(value) shl OwnsObjectsBitIndex);
690704
end;
691705

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,19 @@ constructor TMultiMapBase<TKey, TValue>.Create(
536536
const keyComparer: IEqualityComparer<TKey>;
537537
ownerships: TDictionaryOwnerships);
538538
begin
539+
{$IFDEF DELPHIXE7_UP}
540+
if GetTypeKind(TKey) <> tkClass then
541+
{$ELSE}
539542
if TType.Kind<TKey> <> tkClass then
543+
{$ENDIF}
540544
if doOwnsKeys in ownerships then
541545
RaiseHelper.NoClassType(TypeInfo(TKey));
542546

547+
{$IFDEF DELPHIXE7_UP}
548+
if GetTypeKind(TValue) <> tkClass then
549+
{$ELSE}
543550
if TType.Kind<TValue> <> tkClass then
551+
{$ENDIF}
544552
if doOwnsValues in ownerships then
545553
RaiseHelper.NoClassType(TypeInfo(TValue));
546554

@@ -953,11 +961,19 @@ constructor THashMultiMap<TKey, TValue>.Create(
953961
const valueComparer: IEqualityComparer<TValue>;
954962
ownerships: TDictionaryOwnerships);
955963
begin
964+
{$IFDEF DELPHIXE7_UP}
965+
if GetTypeKind(TKey) <> tkClass then
966+
{$ELSE}
956967
if TType.Kind<TKey> <> tkClass then
968+
{$ENDIF}
957969
if doOwnsKeys in ownerships then
958970
RaiseHelper.NoClassType(TypeInfo(TKey));
959971

972+
{$IFDEF DELPHIXE7_UP}
973+
if GetTypeKind(TValue) <> tkClass then
974+
{$ELSE}
960975
if TType.Kind<TValue> <> tkClass then
976+
{$ENDIF}
961977
if doOwnsValues in ownerships then
962978
RaiseHelper.NoClassType(TypeInfo(TValue));
963979

@@ -985,11 +1001,19 @@ constructor TTreeMultiMap<TKey, TValue>.Create(
9851001
const keyComparer: IEqualityComparer<TKey>;
9861002
const valueComparer: IComparer<TValue>; ownerships: TDictionaryOwnerships);
9871003
begin
1004+
{$IFDEF DELPHIXE7_UP}
1005+
if GetTypeKind(TKey) <> tkClass then
1006+
{$ELSE}
9881007
if TType.Kind<TKey> <> tkClass then
1008+
{$ENDIF}
9891009
if doOwnsKeys in ownerships then
9901010
RaiseHelper.NoClassType(TypeInfo(TKey));
9911011

1012+
{$IFDEF DELPHIXE7_UP}
1013+
if GetTypeKind(TValue) <> tkClass then
1014+
{$ELSE}
9921015
if TType.Kind<TValue> <> tkClass then
1016+
{$ENDIF}
9931017
if doOwnsValues in ownerships then
9941018
RaiseHelper.NoClassType(TypeInfo(TValue));
9951019

@@ -1030,11 +1054,19 @@ constructor TFoldedListMultiMap<TKey, TValue>.Create(keyType,
10301054
valueType, elementType: PTypeInfo; const keyComparer: IEqualityComparer<TKey>;
10311055
ownerships: TDictionaryOwnerships);
10321056
begin
1057+
{$IFDEF DELPHIXE7_UP}
1058+
if GetTypeKind(TKey) <> tkClass then
1059+
{$ELSE}
10331060
if TType.Kind<TKey> <> tkClass then
1061+
{$ENDIF}
10341062
if doOwnsKeys in ownerships then
10351063
RaiseHelper.NoClassType(keyType);
10361064

1065+
{$IFDEF DELPHIXE7_UP}
1066+
if GetTypeKind(TValue) <> tkClass then
1067+
{$ELSE}
10371068
if TType.Kind<TValue> <> tkClass then
1069+
{$ENDIF}
10381070
if doOwnsValues in ownerships then
10391071
RaiseHelper.NoClassType(valueType);
10401072

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,21 @@ function TAbstractStack<T>.GetCapacity: Integer;
172172

173173
function TAbstractStack<T>.GetCount: Integer;
174174
begin
175+
{$IFDEF DELPHIXE7_UP}
176+
if GetTypeKind(T) <> tkClass then
177+
Result := fCount
178+
else
179+
{$ENDIF}
175180
Result := fCount and CountMask;
176181
end;
177182

178183
function TAbstractStack<T>.GetCountFast: Integer;
179184
begin
185+
{$IFDEF DELPHIXE7_UP}
186+
if GetTypeKind(T) <> tkClass then
187+
Result := fCount
188+
else
189+
{$ENDIF}
180190
Result := fCount and CountMask;
181191
end;
182192

@@ -313,7 +323,11 @@ procedure TAbstractStack<T>.SetCapacity(value: Integer);
313323

314324
procedure TAbstractStack<T>.SetOwnsObjects(const value: Boolean);
315325
begin
316-
if GetElementType.Kind = tkClass then
326+
{$IFDEF DELPHIXE7_UP}
327+
if GetTypeKind(T) = tkClass then
328+
{$ELSE}
329+
if TType.Kind<T> = tkClass then
330+
{$ENDIF}
317331
fCount := (fCount and CountMask) or (Ord(value) shl OwnsObjectsBitIndex);
318332
end;
319333

0 commit comments

Comments
 (0)