Skip to content

Commit c0412e0

Browse files
committed
optimized use of Result
1 parent 5488f88 commit c0412e0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,22 +3262,26 @@ function TIteratorBlock<T>.MoveNextIndexed: Boolean;
32623262

32633263
function TIteratorBlock<T>.MoveNextOrdered: Boolean;
32643264
begin
3265-
Result := Index < Count;
3266-
if Result then
3265+
if Index < Count then
32673266
begin
32683267
Current := Items[Index];
32693268
Inc(Index);
3270-
end;
3269+
Result := True;
3270+
end
3271+
else
3272+
Result := False;
32713273
end;
32723274

32733275
function TIteratorBlock<T>.MoveNextReversed: Boolean;
32743276
begin
3275-
Result := Count > 0;
3276-
if Result then
3277+
if Count > 0 then
32773278
begin
32783279
Dec(Count);
32793280
Current := Items[Count];
3280-
end;
3281+
Result := True;
3282+
end
3283+
else
3284+
Result := False;
32813285
end;
32823286

32833287
function TIteratorBlock<T>.MoveNextSkipWhile: Boolean;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,10 @@ function TSelectIterator<TSource, TResult>.TryGetElementAt(var value: TResult;
17811781
begin
17821782
Result := fSource.TryGetElementAt(sourceValue, index);
17831783
if Result then
1784+
begin
17841785
value := fSelector(sourceValue);
1786+
Result := True;
1787+
end;
17851788
end;
17861789

17871790
function TSelectIterator<TSource, TResult>.TryGetFirst(var value: TResult): Boolean;
@@ -1790,7 +1793,10 @@ function TSelectIterator<TSource, TResult>.TryGetFirst(var value: TResult): Bool
17901793
begin
17911794
Result := fSource.TryGetFirst(sourceValue);
17921795
if Result then
1796+
begin
17931797
value := fSelector(sourceValue);
1798+
Result := True;
1799+
end;
17941800
end;
17951801

17961802
function TSelectIterator<TSource, TResult>.TryGetLast(var value: TResult): Boolean;
@@ -1799,14 +1805,20 @@ function TSelectIterator<TSource, TResult>.TryGetLast(var value: TResult): Boole
17991805
begin
18001806
Result := fSource.TryGetLast(sourceValue);
18011807
if Result then
1808+
begin
18021809
value := fSelector(sourceValue);
1810+
Result := True;
1811+
end;
18031812
end;
18041813

18051814
function TSelectIterator<TSource, TResult>.TryMoveNext(var current: TResult): Boolean;
18061815
begin
18071816
Result := fEnumerator.MoveNext;
18081817
if Result then
1818+
begin
18091819
current := fSelector(fEnumerator.Current);
1820+
Result := True;
1821+
end;
18101822
end;
18111823

18121824
procedure TSelectIterator<TSource, TResult>.Start;

0 commit comments

Comments
 (0)