From fbfa61da5dcb0582887eb51f0c57be96b6cfc48d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 7 Sep 2016 13:09:30 +0300 Subject: [PATCH] Drop K(Mutable)Property{0,1,2}Augmented Also store name in KPropertyImpl, so that calling 'name' on a KProperty instance in the property delegate does not result in unnecessary descriptor computation --- .../internal/KPropertyFromReferenceImpl.kt | 55 ------------------- .../reflect/jvm/internal/KPropertyImpl.kt | 4 +- .../jvm/internal/ReflectionFactoryImpl.java | 18 +++--- 3 files changed, 12 insertions(+), 65 deletions(-) delete mode 100644 core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyFromReferenceImpl.kt diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyFromReferenceImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyFromReferenceImpl.kt deleted file mode 100644 index 8abc6b16c47..00000000000 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyFromReferenceImpl.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.reflect.jvm.internal - -import kotlin.jvm.internal.* - -internal open class KProperty0Augmented( - val reference: PropertyReference0 -) : KProperty0Impl(reference.owner as KDeclarationContainerImpl, reference.name, reference.signature) { - override val name: String get() = reference.name -} - -internal open class KMutableProperty0Augmented( - val reference: MutablePropertyReference0 -) : KMutableProperty0Impl(reference.owner as KDeclarationContainerImpl, reference.name, reference.signature) { - override val name: String get() = reference.name -} - -internal open class KProperty1Augmented( - val reference: PropertyReference1 -) : KProperty1Impl(reference.owner as KDeclarationContainerImpl, reference.name, reference.signature) { - override val name: String get() = reference.name -} - -internal open class KMutableProperty1Augmented( - val reference: MutablePropertyReference1 -) : KMutableProperty1Impl(reference.owner as KDeclarationContainerImpl, reference.name, reference.signature) { - override val name: String get() = reference.name -} - -internal open class KProperty2Augmented( - val reference: PropertyReference2 -) : KProperty2Impl(reference.owner as KDeclarationContainerImpl, reference.name, reference.signature) { - override val name: String get() = reference.name -} - -internal open class KMutableProperty2Augmented( - val reference: MutablePropertyReference2 -) : KMutableProperty2Impl(reference.owner as KDeclarationContainerImpl, reference.name, reference.signature) { - override val name: String get() = reference.name -} diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt index 1752a79c465..dad6a6036a5 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KPropertyImpl.kt @@ -33,7 +33,7 @@ import kotlin.reflect.jvm.internal.JvmPropertySignature.* internal abstract class KPropertyImpl private constructor( override val container: KDeclarationContainerImpl, - name: String, + override val name: String, val signature: String, descriptorInitialValue: PropertyDescriptor? ) : KProperty, KCallableImpl { @@ -85,8 +85,6 @@ internal abstract class KPropertyImpl private constructor( override val descriptor: PropertyDescriptor get() = descriptor_() - override val name: String get() = descriptor.name.asString() - override val caller: FunctionCaller<*> get() = getter.caller override val defaultCaller: FunctionCaller<*>? get() = getter.defaultCaller diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java index 36061d5b2c8..26ad1e53926 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java @@ -19,7 +19,6 @@ package kotlin.reflect.jvm.internal; import kotlin.jvm.internal.*; import kotlin.reflect.*; import kotlin.reflect.jvm.ReflectLambdaKt; -import org.jetbrains.kotlin.descriptors.FunctionDescriptor; /** * @suppress @@ -74,31 +73,36 @@ public class ReflectionFactoryImpl extends ReflectionFactory { @Override public KProperty0 property0(PropertyReference0 p) { - return new KProperty0Augmented(p); + return new KProperty0Impl(getOwner(p), p.getName(), p.getSignature()); } @Override public KMutableProperty0 mutableProperty0(MutablePropertyReference0 p) { - return new KMutableProperty0Augmented(p); + return new KMutableProperty0Impl(getOwner(p), p.getName(), p.getSignature()); } @Override public KProperty1 property1(PropertyReference1 p) { - return new KProperty1Augmented(p); + return new KProperty1Impl(getOwner(p), p.getName(), p.getSignature()); } @Override public KMutableProperty1 mutableProperty1(MutablePropertyReference1 p) { - return new KMutableProperty1Augmented(p); + return new KMutableProperty1Impl(getOwner(p), p.getName(), p.getSignature()); } @Override public KProperty2 property2(PropertyReference2 p) { - return new KProperty2Augmented(p); + return new KProperty2Impl(getOwner(p), p.getName(), p.getSignature()); } @Override public KMutableProperty2 mutableProperty2(MutablePropertyReference2 p) { - return new KMutableProperty2Augmented(p); + return new KMutableProperty2Impl(getOwner(p), p.getName(), p.getSignature()); + } + + private static KDeclarationContainerImpl getOwner(CallableReference reference) { + KDeclarationContainer owner = reference.getOwner(); + return owner instanceof KDeclarationContainerImpl ? ((KDeclarationContainerImpl) owner) : EmptyContainerForLocal.INSTANCE; } }