Don't write false values in SetSlice to binding context
Optimization is significant for USED_AS_RESULT_OF_LAMBDA slice
This commit is contained in:
+2
-5
@@ -21,10 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.util.slicedMap.BasicWritableSlice;
|
||||
import org.jetbrains.kotlin.util.slicedMap.MutableSlicedMap;
|
||||
import org.jetbrains.kotlin.util.slicedMap.SlicedMapImpl;
|
||||
import org.jetbrains.kotlin.util.slicedMap.Slices;
|
||||
import org.jetbrains.kotlin.util.slicedMap.*;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
|
||||
@@ -47,7 +44,7 @@ public final class JvmSerializationBindings {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class SerializationMappingSetSlice<K> extends Slices.SetSlice<K> {
|
||||
private static final class SerializationMappingSetSlice<K> extends SetSlice<K> {
|
||||
public SerializationMappingSetSlice() {
|
||||
super(Slices.ONLY_REWRITE_TO_EQUAL, false);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public interface BindingContext {
|
||||
|
||||
WritableSlice<Box<DeferredType>, Boolean> DEFERRED_TYPE = Slices.createCollectiveSetSlice();
|
||||
|
||||
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new Slices.SetSlice<PropertyDescriptor>(DO_NOTHING) {
|
||||
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new SetSlice<PropertyDescriptor>(DO_NOTHING) {
|
||||
@Override
|
||||
public Boolean computeValue(
|
||||
SlicedMap map,
|
||||
@@ -191,7 +191,7 @@ public interface BindingContext {
|
||||
};
|
||||
WritableSlice<PropertyDescriptor, Boolean> IS_UNINITIALIZED = Slices.createSimpleSetSlice();
|
||||
|
||||
WritableSlice<KtLambdaExpression, Boolean> BLOCK = new Slices.SetSlice<KtLambdaExpression>(DO_NOTHING) {
|
||||
WritableSlice<KtLambdaExpression, Boolean> BLOCK = new SetSlice<KtLambdaExpression>(DO_NOTHING) {
|
||||
@Override
|
||||
public Boolean computeValue(SlicedMap map, KtLambdaExpression expression, Boolean isBlock, boolean valueNotFound) {
|
||||
isBlock = valueNotFound ? false : isBlock;
|
||||
|
||||
@@ -119,9 +119,9 @@ public class DelegatingBindingTrace implements BindingTrace {
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
V value = map.get(slice, key);
|
||||
if (slice instanceof Slices.SetSlice) {
|
||||
if (slice instanceof SetSlice) {
|
||||
assert value != null;
|
||||
if (value.equals(true)) return value;
|
||||
if (!value.equals(SetSlice.DEFAULT)) return value;
|
||||
}
|
||||
else if (value != null) {
|
||||
return value;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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 org.jetbrains.kotlin.util.slicedMap
|
||||
|
||||
|
||||
open class SetSlice<K> @JvmOverloads constructor(rewritePolicy: RewritePolicy, isCollective: Boolean = false) :
|
||||
BasicWritableSlice<K, Boolean>(rewritePolicy, isCollective) {
|
||||
companion object {
|
||||
@JvmField
|
||||
val DEFAULT = false
|
||||
}
|
||||
|
||||
override fun check(key: K, value: Boolean?): Boolean {
|
||||
assert(value != null) { this.toString() + " called with null value" }
|
||||
return value != DEFAULT
|
||||
}
|
||||
|
||||
override fun computeValue(map: SlicedMap?, key: K, value: Boolean?, valueNotFound: Boolean): Boolean? {
|
||||
val result = super.computeValue(map, key, value, valueNotFound)
|
||||
return result ?: DEFAULT
|
||||
}
|
||||
|
||||
override fun makeRawValueVersion(): ReadOnlySlice<K, Boolean>? {
|
||||
return object : DelegatingSlice<K, Boolean>(this) {
|
||||
override fun computeValue(map: SlicedMap, key: K, value: Boolean?, valueNotFound: Boolean): Boolean? {
|
||||
if (valueNotFound) return DEFAULT
|
||||
return value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,22 +118,4 @@ public class Slices {
|
||||
return new BasicWritableSlice<K, V>(rewritePolicy);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SetSlice<K> extends BasicWritableSlice<K, Boolean> {
|
||||
|
||||
protected SetSlice(RewritePolicy rewritePolicy) {
|
||||
this(rewritePolicy, false);
|
||||
}
|
||||
|
||||
protected SetSlice(RewritePolicy rewritePolicy, boolean collective) {
|
||||
super(rewritePolicy, collective);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean computeValue(SlicedMap map, K key, Boolean value, boolean valueNotFound) {
|
||||
Boolean result = super.computeValue(map, key, value, valueNotFound);
|
||||
return result != null ? result : false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user