Skip to content

Commit

Permalink
Use dedicated equals method for univerval equality of chars (#18770)
Browse files Browse the repository at this point in the history
Uses `BoxesRunTime.equalsNumChar` instead of
`BoxesRunTime.equalsNumObject` for boxed Char universal equality checks.
This method was private in Scala 2.11, but is available since 2.12
allowing us to better optimize universal equality checks made with
`Char`
 
 Change was reflected in both JVM and JS backend (also the test sources)
  • Loading branch information
sjrd authored Oct 27, 2023
2 parents 93a2924 + 733b8bb commit 835bdb4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
val equalsMethod: Symbol = {
if (l.tpe <:< defn.BoxedNumberClass.info) {
if (r.tpe <:< defn.BoxedNumberClass.info) defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
else if (r.tpe <:< defn.BoxedCharClass.info) NoSymbol // ctx.requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
else if (r.tpe <:< defn.BoxedCharClass.info) defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumChar)
else defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
} else defn.BoxesRunTimeModule_externalEquals
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ class JSCodeGen()(using genCtx: Context) {
private lazy val externalEqualsNumNum: Symbol =
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
private lazy val externalEqualsNumChar: Symbol =
NoSymbol // requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumChar)
private lazy val externalEqualsNumObject: Symbol =
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
private lazy val externalEquals: Symbol =
Expand Down Expand Up @@ -2885,7 +2885,7 @@ class JSCodeGen()(using genCtx: Context) {
val ptfm = ctx.platform
if (lsym.derivesFrom(defn.BoxedNumberClass)) {
if (rsym.derivesFrom(defn.BoxedNumberClass)) externalEqualsNumNum
else if (rsym.derivesFrom(defn.BoxedCharClass)) externalEqualsNumObject // will be externalEqualsNumChar in 2.12, SI-9030
else if (rsym.derivesFrom(defn.BoxedCharClass)) externalEqualsNumChar
else externalEqualsNumObject
} else externalEquals
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
val equalsMethod: Symbol = {
if (l.tpe <:< defn.BoxedNumberClass.info) {
if (r.tpe <:< defn.BoxedNumberClass.info) defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
else if (r.tpe <:< defn.BoxedCharClass.info) NoSymbol // ctx.requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
else if (r.tpe <:< defn.BoxedCharClass.info) defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumChar)
else defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
} else defn.BoxesRunTimeModule_externalEquals
}
Expand Down
4 changes: 2 additions & 2 deletions tests/pos-with-compiler-cc/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,7 @@ class JSCodeGen()(using genCtx: DetachedContext) {
private lazy val externalEqualsNumNum: Symbol =
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
private lazy val externalEqualsNumChar: Symbol =
NoSymbol // requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumChar)
private lazy val externalEqualsNumObject: Symbol =
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
private lazy val externalEquals: Symbol =
Expand Down Expand Up @@ -2886,7 +2886,7 @@ class JSCodeGen()(using genCtx: DetachedContext) {
val ptfm = ctx.platform
if (lsym.derivesFrom(defn.BoxedNumberClass)) {
if (rsym.derivesFrom(defn.BoxedNumberClass)) externalEqualsNumNum
else if (rsym.derivesFrom(defn.BoxedCharClass)) externalEqualsNumObject // will be externalEqualsNumChar in 2.12, SI-9030
else if (rsym.derivesFrom(defn.BoxedCharClass)) externalEqualsNumChar
else externalEqualsNumObject
} else externalEquals
}
Expand Down

0 comments on commit 835bdb4

Please sign in to comment.