Optimize Annotations.isEmpty in some implementations
This commit is contained in:
+2
-2
@@ -222,7 +222,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(flags)) {
|
||||
return Annotations.EMPTY
|
||||
}
|
||||
return DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
|
||||
return NonEmptyDeserializedAnnotationsWithPossibleTargets(c.storageManager) {
|
||||
c.containingDeclaration.asProtoContainer()?.let {
|
||||
c.components.annotationAndConstantLoader.loadCallableAnnotations(it, proto, kind).toList()
|
||||
}.orEmpty()
|
||||
@@ -255,7 +255,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
return valueParameters.mapIndexed { i, proto ->
|
||||
val flags = if (proto.hasFlags()) proto.flags else 0
|
||||
val annotations = if (containerOfCallable != null && Flags.HAS_ANNOTATIONS.get(flags)) {
|
||||
DeserializedAnnotations(c.storageManager) {
|
||||
NonEmptyDeserializedAnnotations(c.storageManager) {
|
||||
c.components.annotationAndConstantLoader
|
||||
.loadValueParameterAnnotations(containerOfCallable, callable, kind, i, proto)
|
||||
.toList()
|
||||
|
||||
+16
-2
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
|
||||
class DeserializedAnnotations(
|
||||
open class DeserializedAnnotations(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationDescriptor>
|
||||
) : Annotations {
|
||||
@@ -43,7 +43,14 @@ class DeserializedAnnotations(
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> = annotations.iterator()
|
||||
}
|
||||
|
||||
class DeserializedAnnotationsWithPossibleTargets(
|
||||
class NonEmptyDeserializedAnnotations(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationDescriptor>
|
||||
) : DeserializedAnnotations(storageManager, compute) {
|
||||
override fun isEmpty(): Boolean = false
|
||||
}
|
||||
|
||||
open class DeserializedAnnotationsWithPossibleTargets(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationWithTarget>
|
||||
) : Annotations {
|
||||
@@ -64,3 +71,10 @@ class DeserializedAnnotationsWithPossibleTargets(
|
||||
return annotations.asSequence().filter { it.target == null }.map { it.annotation }.iterator()
|
||||
}
|
||||
}
|
||||
|
||||
class NonEmptyDeserializedAnnotationsWithPossibleTargets(
|
||||
storageManager: StorageManager,
|
||||
compute: () -> List<AnnotationWithTarget>
|
||||
) : DeserializedAnnotationsWithPossibleTargets(storageManager, compute) {
|
||||
override fun isEmpty(): Boolean = false
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ class DeserializedClassDescriptor(
|
||||
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
|
||||
Annotations.EMPTY
|
||||
}
|
||||
else DeserializedAnnotations(c.storageManager) {
|
||||
else NonEmptyDeserializedAnnotations(c.storageManager) {
|
||||
c.components.annotationAndConstantLoader.loadClassAnnotations(thisAsProtoContainer).toList()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user