8000 cache toASMType · scala/scala@29d8466 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 29d8466

Browse files
committed
cache toASMType
1 parent 914fdfa commit 29d8466

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -471,28 +471,17 @@ abstract class BTypes {
471471
* - for an OBJECT type, the 'L' and ';' are not part of the range of the created Type
472472
* - for an ARRAY type, the full descriptor is part of the range
473473
*/
474-
def toASMType: asm.Type = this match {
475-
case UNIT => asm.Type.VOID_TYPE
476-
case BOOL => asm.Type.BOOLEAN_TYPE
477-
case CHAR => asm.Type.CHAR_TYPE
478-
case BYTE => asm.Type.BYTE_TYPE
479-
case SHORT => asm.Type.SHORT_TYPE
480-
case INT => asm.Type.INT_TYPE
481-
case FLOAT => asm.Type.FLOAT_TYPE
482-
case LONG => asm.Type.LONG_TYPE
483-
case DOUBLE => asm.Type.DOUBLE_TYPE
484-
case ClassBType(internalName) => asm.Type.getObjectType(internalName) // see (*) above
485-
case a: ArrayBType => asm.Type.getObjectType(a.descriptor)
486-
case m: MethodBType => asm.Type.getMethodType(m.descriptor)
487-
}
474+
def toASMType: asm.Type
488475

489476
def asRefBType : RefBType = this.asInstanceOf[RefBType]
490477
def asArrayBType : ArrayBType = this.asInstanceOf[ArrayBType]
491478
def asClassBType : ClassBType = this.asInstanceOf[ClassBType]
492479
def asPrimitiveBType : PrimitiveBType = this.asInstanceOf[PrimitiveBType]
493480
}
494481

495-
sealed abstract class PrimitiveBType(override val descriptor:String) extends BType {
482+
sealed abstract class PrimitiveBType(
483+
override val descriptor:String,
484+
override val toASMType: asm.Type) extends BType {
496485
private[BTypes] override def buildDescriptor(sb: java.lang.StringBuilder): Unit = {
497486
sb.append(descriptor)
498487
}
@@ -560,15 +549,15 @@ abstract class BTypes {
560549
}
561550
}
562551

563-
case object UNIT extends PrimitiveBType("V")
564-
case object BOOL extends PrimitiveBType("Z")
565-
case object CHAR extends PrimitiveBType("C")
566-
case object BYTE extends PrimitiveBType("B")
567-
case object SHORT extends PrimitiveBType("S")
568-
case object INT extends PrimitiveBType("I")
569-
case object FLOAT extends PrimitiveBType("F")
570-
case object LONG extends PrimitiveBType("J")
571-
case object DOUBLE extends PrimitiveBType("D")
552+
case object UNIT extends PrimitiveBType("V",asm.Type.VOID_TYPE)
553+
case object BOOL extends PrimitiveBType("Z",asm.Type.BOOLEAN_TYPE)
554+
case object CHAR extends PrimitiveBType("C",asm.Type.CHAR_TYPE)
555+
case object BYTE extends PrimitiveBType("B",asm.Type.BYTE_TYPE)
556+
case object SHORT extends PrimitiveBType("S",asm.Type.SHORT_TYPE)
557+
case object INT extends PrimitiveBType("I",asm.Type.INT_TYPE)
558+
case object FLOAT extends PrimitiveBType("F",asm.Type.FLOAT_TYPE)
559+
case object LONG extends PrimitiveBType("J",asm.Type.LONG_TYPE)
560+
case object DOUBLE extends PrimitiveBType("D",asm.Type.DOUBLE_TYPE)
572561

573562
sealed trait RefBType extends BType {
574563
/**
@@ -863,6 +852,16 @@ abstract class BTypes {
863852
descriptorCache = sb.substring(start)
864853
} else sb.append(descriptorCache)
865854

855+
856+
/**
857+
* The asm.Type corresponding to this BType.
858+
*
859+
* Note about asm.Type.getObjectType (*): For class types, the method expects the internal
860+
* name, i.e. without the surrounding 'L' and ';'.
861+
*/
862+
override lazy val toASMType = asm.Type.getObjectType(internalName)
863+
864+
866865
/**
867866
* Write-once variable allows initializing a cyclic graph of infos. This is required for
868867
* nested classes. Example: for the definition `class A { class B }` we have
@@ -1132,6 +1131,15 @@ abstract class BTypes {
11321131
descriptorCache = sb.substring(start)
11331132
} else sb.append(descriptorCache)
11341133

1134+
1135+
/**
1136+
* For array types on the other hand, the method expects a full descriptor,
1137+
* for example "[Ljava/lang/String;".
1138+
*
1139+
*/
1140+
override lazy val toASMType = asm.Type.getObjectType(descriptor)
1141+
1142+
11351143
def dimension: Int = componentType match {
11361144
case a: ArrayBType => 1 + a.dimension
11371145
case _ => 1
@@ -1163,6 +1171,8 @@ abstract class BTypes {
11631171
descriptorCache = sb.substring(start)
11641172

11651173
} else sb.append(descriptorCache)
1174+
1175+
override lazy val toASMType = asm.Type.getMethodType(descriptor)
11661176
}
11671177

11681178
/* Some definitions that are required for the implementation of BTypes. They are abstract because

0 commit comments

Comments
 (0)
0