Skip to content

Commit be1965c

Browse files
committed
Use more efficient type comparisons
isRef is more efficient than subtyping check.
1 parent 0670fc3 commit be1965c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
348348
def initValue(tpe: Types.Type)(implicit ctx: Context) = {
349349
val tpw = tpe.widen
350350

351-
if (tpw =:= defn.IntType) Literal(Constant(0))
352-
else if (tpw =:= defn.LongType) Literal(Constant(0L))
353-
else if (tpw =:= defn.BooleanType) Literal(Constant(false))
354-
else if (tpw =:= defn.CharType) Literal(Constant('\u0000'))
355-
else if (tpw =:= defn.FloatType) Literal(Constant(0f))
356-
else if (tpw =:= defn.DoubleType) Literal(Constant(0d))
357-
else if (tpw =:= defn.ByteType) Literal(Constant(0.toByte))
358-
else if (tpw =:= defn.ShortType) Literal(Constant(0.toShort))
351+
if (tpw isRef defn.IntClass) Literal(Constant(0))
352+
else if (tpw isRef defn.LongClass) Literal(Constant(0L))
353+
else if (tpw isRef defn.BooleanClass) Literal(Constant(false))
354+
else if (tpw isRef defn.CharClass) Literal(Constant('\u0000'))
355+
else if (tpw isRef defn.FloatClass) Literal(Constant(0f))
356+
else if (tpw isRef defn.DoubleClass) Literal(Constant(0d))
357+
else if (tpw isRef defn.ByteClass) Literal(Constant(0.toByte))
358+
else if (tpw isRef defn.ShortClass) Literal(Constant(0.toShort))
359359
else Literal(Constant(null)).select(defn.Any_asInstanceOf).appliedToType(tpe)
360360
}
361361

src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ class LazyValTranformContext {
8888
val tpe = x.tpe.widen
8989

9090
val holderType =
91-
if (tpe =:= defn.IntType) "LazyInt"
92-
else if (tpe =:= defn.LongType) "LazyLong"
93-
else if (tpe =:= defn.BooleanType) "LazyBoolean"
94-
else if (tpe =:= defn.FloatType) "LazyFloat"
95-
else if (tpe =:= defn.DoubleType) "LazyDouble"
96-
else if (tpe =:= defn.ByteType) "LazyByte"
97-
else if (tpe =:= defn.CharType) "LazyChar"
98-
else if (tpe =:= defn.ShortType) "LazyShort"
91+
if (tpe isRef defn.IntClass) "LazyInt"
92+
else if (tpe isRef defn.LongClass) "LazyLong"
93+
else if (tpe isRef defn.BooleanClass) "LazyBoolean"
94+
else if (tpe isRef defn.FloatClass) "LazyFloat"
95+
else if (tpe isRef defn.DoubleClass) "LazyDouble"
96+
else if (tpe isRef defn.ByteClass) "LazyByte"
97+
else if (tpe isRef defn.CharClass) "LazyChar"
98+
else if (tpe isRef defn.ShortClass) "LazyShort"
9999
else "LazyRef"
100100

101101
val holderImpl = ctx.requiredClass("dotty.runtime." + holderType)

0 commit comments

Comments
 (0)