Skip to content

Commit 12a9b29

Browse files
committed
Optimize functionArity.
1 parent b3f908d commit 12a9b29

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package core
33

44
import java.security.MessageDigest
55
import scala.io.Codec
6+
import Int.MaxValue
67
import Names._, StdNames._, Contexts._, Symbols._, Flags._, NameKinds._, Types._
7-
import scala.internal.Chars
8-
import Chars.isOperatorPart
8+
import scala.internal.Chars.{isOperatorPart, digit2int}
99
import Definitions._
1010
import nme._
1111
import Decorators.concat
@@ -207,14 +207,18 @@ object NameOps {
207207

208208
/** Parsed function arity for function with some specific prefix */
209209
private def functionArityFor(prefix: String): Int =
210-
if (name.startsWith(prefix)) {
211-
val suffix = name.toString.substring(prefix.length)
212-
if (suffix.matches("\\d+"))
213-
suffix.toInt
210+
inline val MaxSafeInt = MaxValue / 10
211+
val first = name.firstPart
212+
def collectDigits(acc: Int, idx: Int): Int =
213+
if idx == first.length then acc
214214
else
215-
-1
216-
}
217-
else -1
215+
val d = digit2int(first(idx), 10)
216+
if d < 0 || acc > MaxSafeInt then -1
217+
else collectDigits(acc * 10 + d, idx + 1)
218+
if first.startsWith(prefix) && prefix.length < first.length then
219+
collectDigits(0, prefix.length)
220+
else
221+
-1
218222

219223
/** The name of the generic runtime operation corresponding to an array operation */
220224
def genericArrayOp: TermName = name match {

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,6 @@ object TypeComparer {
25012501
case _ => String.valueOf(res)
25022502
}
25032503

2504-
25052504
/** The approximation state indicates how the pair of types currently compared
25062505
* relates to the types compared originally.
25072506
* - `None` : They are still the same types

0 commit comments

Comments
 (0)