Skip to content

Commit dff2675

Browse files
authored
Merge pull request scala/scala#10903 from som-snytt/issue/13052-slice-overflow
Split the SliceIterator on drop overflow [ci: last-only]
2 parents 1954ca6 + e7bd9a2 commit dff2675

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

library/src/scala/collection/Iterator.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,12 +1257,15 @@ object Iterator extends IterableFactory[Iterator] {
12571257
else if (until <= lo) 0 // empty
12581258
else if (unbounded) until - lo // now finite
12591259
else adjustedBound min (until - lo) // keep lesser bound
1260+
val sum = dropping + lo
12601261
if (rest == 0) empty
1262+
else if (sum < 0) {
1263+
dropping = Int.MaxValue
1264+
remaining = 0
1265+
this.concat(new SliceIterator(underlying, start = sum - Int.MaxValue, limit = rest))
1266+
}
12611267
else {
1262-
dropping = {
1263-
val sum = dropping + lo
1264-
if (sum < 0) Int.MaxValue else sum
1265-
}
1268+
dropping = sum
12661269
remaining = rest
12671270
this
12681271
}

0 commit comments

Comments
 (0)