Skip to content

Commit e17f382

Browse files
committed
fix: short circuit range next loop
1 parent 9e313d3 commit e17f382

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

NCrontab.Advanced/Filters/RangeFilter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ private bool IsMatch(int evalValue)
9898

9999
var newValue = (int?) value + 1;
100100
while (newValue < max && !IsMatch(newValue.Value))
101+
{
102+
// short circuit, `IsMatch` can never be true
103+
if (newValue > End)
104+
newValue = max;
101105
newValue++;
106+
}
102107

103108
if (newValue > max) newValue = null;
104109

@@ -118,7 +123,12 @@ public int First()
118123

119124
var newValue = 0;
120125
while (newValue < max && !IsMatch(newValue))
126+
{
127+
// short circuit, `IsMatch` can never be true
128+
if (newValue > End)
129+
newValue = max;
121130
newValue++;
131+
}
122132

123133
if (newValue > max)
124134
throw new CrontabException(string.Format("Next value for {0} on field {1} could not be found!",

0 commit comments

Comments
 (0)