8000 minor BTypes optimisations · scala/scala@0e2bed1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e2bed1

Browse files
mkeskellsrorygraves
authored andcommitted
minor BTypes optimisations
1 parent d61301d commit 0e2bed1

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
13571357
val markers = if (addScalaSerializableMarker) classBTypeFromSymbol(definitions.SerializableClass).toASMType :: Nil else Nil
13581358
visitInvokeDynamicInsnLMF(bc.jmethod, sam.name.toString, invokedType, samMethodType, implMethodHandle, constrainedType, isSerializable, markers)
13591359
if (isSerializable)
1360-
addIndyLambdaImplMethod(cnode.name, implMethodHandle :: Nil)
1360+
addIndyLambdaImplMethod(cnode.name, implMethodHandle)
13611361
}
13621362
}
13631363

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,30 @@ abstract class BTypes {
123123
* has the method.
124124
*/
125125
val indyLambdaImplMethods: mutable.AnyRefMap[InternalName, mutable.LinkedHashSet[asm.Handle]] = recordPerRunCache(mutable.AnyRefMap())
126+
127+
/**
128+
* add methods
129+
* @return the added methods. Note the order is undefined
130+
*/
126131
def addIndyLambdaImplMethod(hostClass: InternalName, handle: Seq[asm.Handle]): Seq[asm.Handle] = {
127132
if (handle.isEmpty) Nil else {
128133
val set = indyLambdaImplMethods.getOrElseUpdate(hostClass, mutable.LinkedHashSet())
129-
val added = handle.filterNot(set)
130-
set ++= handle
131-
added
134+
if (set isEmpty) {
135+
set ++= handle
136+
handle
137+
} else {
138+
var added = List.empty[asm.Handle]
139+
handle foreach { h => if (set.add(h)) added ::= h}
140+
added
141+
}
132142
}
133143
}
144+
def addIndyLambdaImplMethod(hostClass: InternalName, handle: asm.Handle): Boolean = {
145+
indyLambdaImplMethods.getOrElseUpdate(hostClass, mutable.LinkedHashSet()).add(handle)
146+
}
134147
def removeIndyLambdaImplMethod(hostClass: InternalName, handle: Seq[asm.Handle]): Unit = {
135148
if (handle.nonEmpty)
136-
indyLambdaImplMethods.getOrElseUpdate(hostClass, mutable.LinkedHashSet()) --= handle
149+
indyLambdaImplMethods.get(hostClass).foreach(_ --= handle)
137150
}
138151

139152
def getIndyLambdaImplMethods(hostClass: InternalName): Iterable[asm.Handle] = {
@@ -258,7 +271,7 @@ abstract class BTypes {
258271
def inlineInfoFromClassfile(classNode: ClassNode): InlineInfo = {
259272
def fromClassfileAttribute: Option[InlineInfo] = {
260273
if (classNode.attrs == null) None
261-
else classNode.attrs.asScala.collect({ case a: InlineInfoAttribute => a}).headOption.map(_.inlineInfo)
274+
else classNode.attrs.asScala.collectFirst{ case a: InlineInfoAttribute => a.inlineInfo}
262275
}
263276

264277
def fromClassfileWithoutAttribute = {
@@ -272,13 +285,13 @@ abstract class BTypes {
272285
// require special handling. Excluding is OK because they are never inlined.
273286
// Here we are parsing from a classfile and we don't need to do anything special. Many of these
274287
// primitives don't even exist, for example Any.isInstanceOf.
275-
val methodInfos = classNode.methods.asScala.map(methodNode => {
288+
val methodInfos:Map[String,MethodInlineInfo] = classNode.methods.asScala.map(methodNode => {
276289
val info = MethodInlineInfo(
277290
effectivelyFinal = BytecodeUtils.isFinalMethod(methodNode),
278291
annotatedInline = false,
279292
annotatedNoInline = false)
280293
(methodNode.name + methodNode.desc, info)
281-
}).toMap
294+
})(scala.collection.breakOut)
282295
InlineInfo(
283296
isEffectivelyFinal = BytecodeUtils.isFinalClass(classNode),
284297
sam = inlinerHeuristics.javaSam(classNode.name),
@@ -896,11 +909,6 @@ abstract class BTypes {
896909
assert(info.get.nestedClasses.forall(c => ifInit(c)(_.isNestedClass.get)), info.get.nestedClasses)
897910
}
898911

899-
/**
900-
* @return The class name without the package prefix
901-
*/
902-
def simpleName: String = internalName.split("/").last
903-
904912
def isInterface: Either[NoClassBTypeInfo, Boolean] = info.map(i => (i.flags & asm.Opcodes.ACC_INTERFACE) != 0)
905913

906914
def superClassesTransitive: Either[NoClassBTypeInfo, List[ClassBType]] = info.flatMap(i => i.superClass match {

0 commit comments

Comments
 (0)
0