Skip to content

Commit 8c42d75

Browse files
committed
Make natSize tailrec to avoid "recursive inlining is too deep"
1 parent bf7249f commit 8c42d75

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TastyBuffer.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import util.Util.dble
88
object TastyBuffer {
99

1010
/** The number of digits of the natural number `nat`, written in base 128 format. */
11-
def natSize(nat: Int): Int =
12-
if (nat < 128) 1 else natSize(nat >>> 7) + 1
11+
def natSize(nat: Int): Int = {
12+
def loop(n: Int, acc: Int): Int =
13+
if (n < 128) acc else loop(n >>> 7, acc + 1)
14+
loop(nat, 1)
15+
}
1316

1417
/** An address pointing to an index in a Tasty buffer's byte array */
1518
case class Addr(index: Int) extends AnyVal {

0 commit comments

Comments
 (0)