Skip to content

Commit acdd036

Browse files
committed
fixed range enumerator
1 parent 5223efb commit acdd036

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ TRangeIterator = class(TEnumerableBase<Integer>,
235235
TEnumerator = record
236236
Vtable: Pointer;
237237
RefCount: Integer;
238-
fCurrent, fMax: Integer;
238+
fCurrent, fEnd: Integer;
239239
function GetCurrent: Integer;
240240
function MoveNext: Boolean;
241241
function _Release: Integer; stdcall;
@@ -1559,8 +1559,8 @@ class function TRangeIterator.TEnumerator.Create(start, count: Integer): IEnumer
15591559
RefCount := 1;
15601560
{$Q-}
15611561
fCurrent := start - 1;
1562+
fEnd := start + count;
15621563
{$IFDEF OVERFLOWCHECKS_ON}{$Q+}{$ENDIF}
1563-
fMax := fCurrent + count;
15641564
end;
15651565
end;
15661566

@@ -1570,9 +1570,15 @@ function TRangeIterator.TEnumerator.GetCurrent: Integer;
15701570
end;
15711571

15721572
function TRangeIterator.TEnumerator.MoveNext: Boolean;
1573-
begin
1574-
Result := fCurrent < fMax;
1575-
Inc(fCurrent, Byte(Result));
1573+
var
1574+
current: Integer;
1575+
begin
1576+
current := fCurrent;
1577+
{$Q-}
1578+
Inc(current);
1579+
{$IFDEF OVERFLOWCHECKS_ON}{$Q+}{$ENDIF}
1580+
fCurrent := current;
1581+
Result := current <> fEnd;
15761582
end;
15771583

15781584
function TRangeIterator.TEnumerator._Release: Integer;

0 commit comments

Comments
 (0)