@@ -244,36 +244,45 @@ object BitSet extends SpecificIterableFactory[Int, BitSet] {
244
244
anyChanges ||= currentWord != oldWord
245
245
i -= 1
246
246
}
247
- if (i < 0 ) {
248
- // all indices >= 0 have had result 0, so the bitset is empty
249
- this .empty
250
- } else {
251
- val minimumNonZeroIndex : Int = i + 1
252
- while (! anyChanges && i >= 0 ) {
253
- val oldWord = word(i)
254
- currentWord = oldWord & ~ bs.word(i)
255
- anyChanges ||= currentWord != oldWord
256
- i -= 1
257
- }
258
- if (anyChanges) {
259
- if (minimumNonZeroIndex == - 1 ) {
260
- this .empty
261
- } else if (minimumNonZeroIndex == 0 ) {
262
- new BitSet1 (currentWord)
263
- } else if (minimumNonZeroIndex == 1 ) {
264
- new BitSet2 (word(0 ) & ~ bs.word(0 ), currentWord)
247
+ i match {
248
+ case - 1 =>
249
+ if (anyChanges) {
250
+ if (currentWord == 0 ) {
251
+ this .empty
252
+ } else {
253
+ new BitSet1 (currentWord)
254
+ }
265
255
} else {
256
+ this
257
+ }
258
+ case 0 =>
259
+ val oldFirstWord = word(0 )
260
+ val firstWord = oldFirstWord & ~ bs.word(0 )
261
+ anyChanges ||= firstWord != oldFirstWord
262
+ if (anyChanges) {
263
+ new BitSet2 (firstWord, currentWord)
264
+ } else {
265
+ this
266
+ }
267
+ case _ =>
268
+ val minimumNonZeroIndex : Int = i + 1
269
+ while (! anyChanges && i >= 0 ) {
270
+ val oldWord = word(i)
271
+ currentWord = oldWord & ~ bs.word(i)
272
+ anyChanges ||= currentWord != oldWord
273
+ i -= 1
274
+ }
275
+ if (anyChanges) {
266
276
val newArray = elems.take(minimumNonZeroIndex + 1 )
267
277
newArray(i + 1 ) = currentWord
268
278
while (i >= 0 ) {
269
279
newArray(i) = word(i) & ~ bs.word(i)
270
280
i -= 1
271
281
}
272
- this .fromBitMaskNoCopy(newArray)
282
+ new BitSetN (newArray)
283
+ } else {
284
+ this
273
285
}
274
- } else {
275
- this
276
- }
277
286
}
278
287
} else {
279
288
var i = bsnwords - 1
@@ -314,36 +323,45 @@ object BitSet extends SpecificIterableFactory[Int, BitSet] {
314
323
anyChanges ||= currentWord != oldWord
315
324
i -= 1
316
325
}
317
- if (i < 0 ) {
318
- // all indices >= 0 have had result 0, so the bitset is empty
319
- if (currentWord == 0 ) this .empty else this .fromBitMaskNoCopy(Array (currentWord))
320
- } else {
321
- val minimumNonZeroIndex : Int = i + 1
322
- while (! anyChanges && i >= 0 ) {
323
- val oldWord = word(i)
324
- currentWord = BitSetOps .computeWordForFilter(pred, isFlipped, oldWord, i)
325
- anyChanges ||= currentWord != oldWord
326
- i -= 1
327
- }
328
- if (anyChanges) {
329
- if (minimumNonZeroIndex == - 1 ) {
330
- this .empty
331
- } else if (minimumNonZeroIndex == 0 ) {
332
- new BitSet1 (currentWord)
333
- } else if (minimumNonZeroIndex == 1 ) {
334
- new BitSet2 (BitSetOps .computeWordForFilter(pred, isFlipped, word(0 ), 0 ), currentWord)
326
+ i match {
327
+ case - 1 =>
328
+ if (anyChanges) {
329
+ if (currentWord == 0 ) {
330
+ this .empty
331
+ } else {
332
+ new BitSet1 (currentWord)
333
+ }
335
334
} else {
335
+ this
336
+ }
337
+ case 0 =>
338
+ val oldFirstWord = word(0 )
339
+ val firstWord = BitSetOps .computeWordForFilter(pred, isFlipped, oldFirstWord, 0 )
340
+ anyChanges ||= firstWord != oldFirstWord
341
+ if (anyChanges) {
342
+ new BitSet2 (firstWord, currentWord)
343
+ } else {
344
+ this
345
+ }
346
+ case _ =>
347
+ val minimumNonZeroIndex : Int = i + 1
348
+ while (! anyChanges && i >= 0 ) {
349
+ val oldWord = word(i)
350
+ currentWord = BitSetOps .computeWordForFilter(pred, isFlipped, oldWord, i)
351
+ anyChanges ||= currentWord != oldWord
352
+ i -= 1
353
+ }
354
+ if (anyChanges) {
336
355
val newArray = elems.take(minimumNonZeroIndex + 1 )
337
356
newArray(i + 1 ) = currentWord
338
357
while (i >= 0 ) {
339
358
newArray(i) = BitSetOps .computeWordForFilter(pred, isFlipped, word(i), i)
340
359
i -= 1
341
360
}
342
- this .fromBitMaskNoCopy(newArray)
361
+ new BitSetN (newArray)
362
+ } else {
363
+ this
343
364
}
344
- } else {
345
- this
346
- }
347
365
}
348
366
}
349
367
0 commit comments