Skip to content

Commit 061a95d

Browse files
Rewrite deeply nested for loop with while loops
The inner closure is hot and couldn't be inlined according the jvm debug info.
1 parent 36cc65a commit 061a95d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,22 @@ object PickleBuffer {
252252
// Convert map so that it maps chunks of ChunkBits size at once
253253
// instead of single bits.
254254
def chunkMap(xs: Array[Long]): FlagMap = {
255-
val chunked = Array.ofDim[Long](
256-
(xs.length + ChunkBits - 1) / ChunkBits, ChunkSize)
257-
for (i <- 0 until chunked.length)
258-
for (j <- 0 until ChunkSize)
259-
for (k <- 0 until ChunkBits)
255+
val size = (xs.length + ChunkBits - 1) / ChunkBits
256+
val chunked = Array.ofDim[Long](size, ChunkSize)
257+
var i = 0
258+
while (i < size) {
259+
var j = 0
260+
while (j < ChunkSize) {
261+
var k = 0
262+
while (k < ChunkBits) {
260263
if ((j & (1 << k)) != 0)
261264
chunked(i)(j) |= xs(i * ChunkBits + k)
265+
k += 1
266+
}
267+
j += 1
268+
}
269+
i += 1
270+
}
262271
chunked
263272
}
264273

0 commit comments

Comments
 (0)