Skip to content

Commit 5119be6

Browse files
committed
Port scala/scala#10437 to scala2-library-cc
This is a Tasty breaking change.
1 parent a1b5446 commit 5119be6

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

scala2-library-cc/src/scala/collection/convert/JavaCollectionWrappers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ private[collection] object JavaCollectionWrappers extends Serializable {
3939
}
4040

4141
@SerialVersionUID(3L)
42-
class JIteratorWrapper[A](val underlying: ju.Iterator[A]) extends AbstractIterator[A] with Iterator[A] with Serializable {
42+
class JIteratorWrapper[A](val underlying: ju.Iterator[A]) extends AbstractIterator[A] with Serializable {
4343
def hasNext = underlying.hasNext
4444
def next() = underlying.next
4545
}
4646

4747
@SerialVersionUID(3L)
48-
class JEnumerationWrapper[A](val underlying: ju.Enumeration[A]) extends AbstractIterator[A] with Iterator[A] with Serializable {
48+
class JEnumerationWrapper[A](val underlying: ju.Enumeration[A]) extends AbstractIterator[A] with Serializable {
4949
def hasNext = underlying.hasMoreElements
5050
def next() = underlying.nextElement
5151
}

scala2-library-cc/src/scala/collection/immutable/ChampCommon.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package scala.collection.immutable
1414

1515

16+
import scala.collection.AbstractIterator
1617
import java.lang.Integer.bitCount
1718
import java.lang.Math.ceil
1819
import java.lang.System.arraycopy
@@ -105,7 +106,7 @@ private[collection] abstract class Node[T <: Node[T]] {
105106
*
106107
* @tparam T the trie node type we are iterating over
107108
*/
108-
private[immutable] abstract class ChampBaseIterator[T <: Node[T]] {
109+
private[immutable] abstract class ChampBaseIterator[A, T <: Node[T]] extends AbstractIterator[A] {
109110

110111
import Node.MaxDepth
111112

@@ -192,7 +193,7 @@ private[immutable] abstract class ChampBaseIterator[T <: Node[T]] {
192193
*
193194
* @tparam T the trie node type we are iterating over
194195
*/
195-
private[immutable] abstract class ChampBaseReverseIterator[T <: Node[T]] {
196+
private[immutable] abstract class ChampBaseReverseIterator[A, T <: Node[T]] extends AbstractIterator[A] {
196197

197198
import Node.MaxDepth
198199

scala2-library-cc/src/scala/collection/immutable/HashMap.scala

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,12 @@ private final class BitmapIndexedMapNode[K, +V](
699699
if ((dataMap & bitpos) != 0) {
700700
val index = indexFrom(dataMap, mask, bitpos)
701701
val payload = getPayload(index)
702-
if (key == payload._1) payload else throw new NoSuchElementException
702+
if (key == payload._1) payload else Iterator.empty.next()
703703
} else if ((nodeMap & bitpos) != 0) {
704704
val index = indexFrom(nodeMap, mask, bitpos)
705705
getNode(index).getTuple(key, originalHash, hash, shift + BitPartitionSize)
706706
} else {
707-
throw new NoSuchElementException
707+
Iterator.empty.next()
708708
}
709709
}
710710

@@ -1873,7 +1873,7 @@ private final class HashCollisionMapNode[K, +V ](
18731873

18741874
def size: Int = content.length
18751875

1876-
def apply(key: K, originalHash: Int, hash: Int, shift: Int): V = get(key, originalHash, hash, shift).getOrElse(throw new NoSuchElementException)
1876+
def apply(key: K, originalHash: Int, hash: Int, shift: Int): V = get(key, originalHash, hash, shift).getOrElse(Iterator.empty.next())
18771877

18781878
def get(key: K, originalHash: Int, hash: Int, shift: Int): Option[V] =
18791879
if (this.hash == hash) {
@@ -1883,7 +1883,7 @@ private final class HashCollisionMapNode[K, +V ](
18831883

18841884
override def getTuple(key: K, originalHash: Int, hash: Int, shift: Int): (K, V) = {
18851885
val index = indexOf(key)
1886-
if (index >= 0) content(index) else throw new NoSuchElementException
1886+
if (index >= 0) content(index) else Iterator.empty.next()
18871887
}
18881888

18891889
def getOrElse[V1 >: V](key: K, originalHash: Int, hash: Int, shift: Int, f: => V1): V1 = {
@@ -2096,11 +2096,10 @@ private final class HashCollisionMapNode[K, +V ](
20962096
}
20972097

20982098
private final class MapKeyIterator[K, V](rootNode: MapNode[K, V])
2099-
extends ChampBaseIterator[MapNode[K, V]](rootNode) with Iterator[K] {
2099+
extends ChampBaseIterator[K, MapNode[K, V]](rootNode) {
21002100

21012101
def next() = {
2102-
if (!hasNext)
2103-
throw new NoSuchElementException
2102+
if (!hasNext) Iterator.empty.next()
21042103

21052104
val key = currentValueNode.getKey(currentValueCursor)
21062105
currentValueCursor += 1
@@ -2111,11 +2110,10 @@ private final class MapKeyIterator[K, V](rootNode: MapNode[K, V])
21112110
}
21122111

21132112
private final class MapValueIterator[K, V](rootNode: MapNode[K, V])
2114-
extends ChampBaseIterator[MapNode[K, V]](rootNode) with Iterator[V] {
2113+
extends ChampBaseIterator[V, MapNode[K, V]](rootNode) {
21152114

21162115
def next() = {
2117-
if (!hasNext)
2118-
throw new NoSuchElementException
2116+
if (!hasNext) Iterator.empty.next()
21192117

21202118
val value = currentValueNode.getValue(currentValueCursor)
21212119
currentValueCursor += 1
@@ -2125,11 +2123,10 @@ private final class MapValueIterator[K, V](rootNode: MapNode[K, V])
21252123
}
21262124

21272125
private final class MapKeyValueTupleIterator[K, V](rootNode: MapNode[K, V])
2128-
extends ChampBaseIterator[MapNode[K, V]](rootNode) with Iterator[(K, V)] {
2126+
extends ChampBaseIterator[(K, V), MapNode[K, V]](rootNode) {
21292127

21302128
def next() = {
2131-
if (!hasNext)
2132-
throw new NoSuchElementException
2129+
if (!hasNext) Iterator.empty.next()
21332130

21342131
val payload = currentValueNode.getPayload(currentValueCursor)
21352132
currentValueCursor += 1
@@ -2140,11 +2137,10 @@ private final class MapKeyValueTupleIterator[K, V](rootNode: MapNode[K, V])
21402137
}
21412138

21422139
private final class MapKeyValueTupleReverseIterator[K, V](rootNode: MapNode[K, V])
2143-
extends ChampBaseReverseIterator[MapNode[K, V]](rootNode) with Iterator[(K, V)] {
2140+
extends ChampBaseReverseIterator[(K, V), MapNode[K, V]](rootNode) {
21442141

21452142
def next() = {
2146-
if (!hasNext)
2147-
throw new NoSuchElementException
2143+
if (!hasNext) Iterator.empty.next()
21482144

21492145
val payload = currentValueNode.getPayload(currentValueCursor)
21502146
currentValueCursor -= 1
@@ -2154,13 +2150,12 @@ private final class MapKeyValueTupleReverseIterator[K, V](rootNode: MapNode[K, V
21542150
}
21552151

21562152
private final class MapKeyValueTupleHashIterator[K, V](rootNode: MapNode[K, V])
2157-
extends ChampBaseReverseIterator[MapNode[K, V]](rootNode) with Iterator[Any] {
2153+
extends ChampBaseReverseIterator[Any, MapNode[K, V]](rootNode) {
21582154
private[this] var hash = 0
21592155
private[this] var value: V = _
21602156
override def hashCode(): Int = MurmurHash3.tuple2Hash(hash, value.##, MurmurHash3.productSeed)
21612157
def next() = {
2162-
if (!hasNext)
2163-
throw new NoSuchElementException
2158+
if (!hasNext) Iterator.empty.next()
21642159

21652160
hash = currentValueNode.getHash(currentValueCursor)
21662161
value = currentValueNode.getValue(currentValueCursor)
@@ -2170,7 +2165,7 @@ private final class MapKeyValueTupleHashIterator[K, V](rootNode: MapNode[K, V])
21702165
}
21712166

21722167
/** Used in HashMap[K, V]#removeAll(HashSet[K]) */
2173-
private final class MapNodeRemoveAllSetNodeIterator[K](rootSetNode: SetNode[K]) extends ChampBaseIterator(rootSetNode) {
2168+
private final class MapNodeRemoveAllSetNodeIterator[K](rootSetNode: SetNode[K]) extends ChampBaseIterator[K, SetNode[K]](rootSetNode) {
21742169
/** Returns the result of immutably removing all keys in `rootSetNode` from `rootMapNode` */
21752170
def removeAll[V](rootMapNode: BitmapIndexedMapNode[K, V]): BitmapIndexedMapNode[K, V] = {
21762171
var curr = rootMapNode
@@ -2186,6 +2181,8 @@ private final class MapNodeRemoveAllSetNodeIterator[K](rootSetNode: SetNode[K])
21862181
}
21872182
curr
21882183
}
2184+
2185+
override def next() = Iterator.empty.next()
21892186
}
21902187

21912188
/**
@@ -2371,7 +2368,7 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
23712368
ensureUnaliased()
23722369
xs match {
23732370
case hm: HashMap[K, V] =>
2374-
new ChampBaseIterator[MapNode[K, V]](hm.rootNode) {
2371+
new ChampBaseIterator[(K, V), MapNode[K, V]](hm.rootNode) {
23752372
while(hasNext) {
23762373
val originalHash = currentValueNode.getHash(currentValueCursor)
23772374
update(
@@ -2384,6 +2381,8 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
23842381
)
23852382
currentValueCursor += 1
23862383
}
2384+
2385+
override def next() = Iterator.empty.next()
23872386
}
23882387
case hm: collection.mutable.HashMap[K, V] =>
23892388
val iter = hm.nodeIterator

scala2-library-cc/src/scala/collection/immutable/HashSet.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,11 +1884,10 @@ private final class HashCollisionSetNode[A](val originalHash: Int, val hash: Int
18841884
}
18851885

18861886
private final class SetIterator[A](rootNode: SetNode[A])
1887-
extends ChampBaseIterator[SetNode[A]](rootNode) with Iterator[A] {
1887+
extends ChampBaseIterator[A, SetNode[A]](rootNode) {
18881888

18891889
def next() = {
1890-
if (!hasNext)
1891-
throw new NoSuchElementException
1890+
if (!hasNext) Iterator.empty.next()
18921891

18931892
val payload = currentValueNode.getPayload(currentValueCursor)
18941893
currentValueCursor += 1
@@ -1899,11 +1898,10 @@ private final class SetIterator[A](rootNode: SetNode[A])
18991898
}
19001899

19011900
private final class SetReverseIterator[A](rootNode: SetNode[A])
1902-
extends ChampBaseReverseIterator[SetNode[A]](rootNode) with Iterator[A] {
1901+
extends ChampBaseReverseIterator[A, SetNode[A]](rootNode) {
19031902

19041903
def next(): A = {
1905-
if (!hasNext)
1906-
throw new NoSuchElementException
1904+
if (!hasNext) Iterator.empty.next()
19071905

19081906
val payload = currentValueNode.getPayload(currentValueCursor)
19091907
currentValueCursor -= 1
@@ -1914,13 +1912,12 @@ private final class SetReverseIterator[A](rootNode: SetNode[A])
19141912
}
19151913

19161914
private final class SetHashIterator[A](rootNode: SetNode[A])
1917-
extends ChampBaseIterator[SetNode[A]](rootNode) with Iterator[AnyRef] {
1915+
extends ChampBaseIterator[AnyRef, SetNode[A]](rootNode) {
19181916
private[this] var hash = 0
19191917
override def hashCode(): Int = hash
19201918

19211919
def next(): AnyRef = {
1922-
if (!hasNext)
1923-
throw new NoSuchElementException
1920+
if (!hasNext) Iterator.empty.next()
19241921

19251922
hash = currentValueNode.getHash(currentValueCursor)
19261923
currentValueCursor += 1
@@ -2089,7 +2086,7 @@ private[collection] final class HashSetBuilder[A] extends ReusableBuilder[A, Has
20892086
ensureUnaliased()
20902087
xs match {
20912088
case hm: HashSet[A] =>
2092-
new ChampBaseIterator[SetNode[A]](hm.rootNode) {
2089+
new ChampBaseIterator[A, SetNode[A]](hm.rootNode) {
20932090
while(hasNext) {
20942091
val originalHash = currentValueNode.getHash(currentValueCursor)
20952092
update(
@@ -2101,6 +2098,7 @@ private[collection] final class HashSetBuilder[A] extends ReusableBuilder[A, Has
21012098
)
21022099
currentValueCursor += 1
21032100
}
2101+
override def next() = Iterator.empty.next()
21042102
}
21052103
case other =>
21062104
val it = other.iterator

scala2-library-cc/src/scala/collection/immutable/Vector.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ private object VectorStatics {
22302230
}
22312231

22322232

2233-
private final class NewVectorIterator[A](v: Vector[A], private[this] var totalLength: Int, private[this] val sliceCount: Int) extends Iterator[A] with java.lang.Cloneable {
2233+
private final class NewVectorIterator[A](v: Vector[A], private[this] var totalLength: Int, private[this] val sliceCount: Int) extends AbstractIterator[A] with java.lang.Cloneable {
22342234

22352235
private[this] var a1: Arr1 = v.prefix1
22362236
private[this] var a2: Arr2 = _

0 commit comments

Comments
 (0)