Skip to content

Commit 3585609

Browse files
committed
Use a SAM type for SparseIntArray.transform
Temporary fix waiting for proper function type specialization
1 parent f101e72 commit 3585609

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler/src/dotty/tools/dotc/util/SparseIntArray.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SparseIntArray:
5252
/** Transform each defined value with transformation `op`.
5353
* The transformation takes the element index and value as parameters.
5454
*/
55-
def transform(op: (Int, Value) => Value): Unit =
55+
def transform(op: Transform): Unit =
5656
root.transform(op, 0)
5757

5858
/** Access to some info about low-level representation */
@@ -71,6 +71,9 @@ class SparseIntArray:
7171
object SparseIntArray:
7272
type Value = Int
7373

74+
trait Transform:
75+
def apply(key: Int, v: Value): Value
76+
7477
private inline val NodeSizeLog = 5
7578
private inline val NodeSize = 1 << NodeSizeLog
7679

@@ -91,7 +94,7 @@ object SparseIntArray:
9194
def isEmpty: Boolean
9295
def keysIterator(offset: Int): Iterator[Int]
9396
def foreachBinding(op: (Int, Value) => Unit, offset: Int): Unit
94-
def transform(op: (Int, Value) => Value, offset: Int): Unit
97+
def transform(op: Transform, offset: Int): Unit
9598
def nodeCount: Int
9699
end Node
97100

@@ -136,7 +139,7 @@ object SparseIntArray:
136139
if contains(i) then op(offset + i, elems(i))
137140
i += 1
138141

139-
def transform(op: (Int, Value) => Value, offset: Int): Unit =
142+
def transform(op: Transform, offset: Int): Unit =
140143
var i = 0
141144
while i < NodeSize do
142145
if contains(i) then elems(i) = op(offset + i, elems(i))
@@ -210,7 +213,7 @@ object SparseIntArray:
210213
elems(i).foreachBinding(op, offset + i * elemSize)
211214
i += 1
212215

213-
def transform(op: (Int, Value) => Value, offset: Int): Unit =
216+
def transform(op: Transform, offset: Int): Unit =
214217
var i = 0
215218
while i < NodeSize do
216219
if elems(i) != null then

0 commit comments

Comments
 (0)