memory optimization: do not allocate empty arrays (part of KTIJ-27475 Investigate Kotlin plugin excessive memory usage)

GitOrigin-RevId: 25de43af6bcce77ad6507809b7cf83ae4e41b44b
This commit is contained in:
Alexey Kudravtsev
2024-02-06 15:55:04 +01:00
committed by intellij-monorepo-bot
parent 6f3fae4c08
commit 32a0b64911
8 changed files with 14 additions and 12 deletions

View File

@@ -16,12 +16,12 @@ final class Component {
final EKey @NotNull [] ids;
Component(@NotNull Value value, @NotNull Collection<EKey> ids) {
this(value, ids.toArray(new EKey[0]));
this(value, ids.toArray(EKey.EMPTY_ARRAY));
}
Component(@NotNull Value value, EKey @NotNull ... ids) {
this.value = value;
this.ids = ids;
this.ids = ids.length == 0 ? EKey.EMPTY_ARRAY : ids;
}
@Override

View File

@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
* Equation key (or variable)
*/
public final class EKey {
public static final EKey[] EMPTY_ARRAY = new EKey[0];
final @NotNull MemberDescriptor member;
final int dirKey;
final boolean stable;

View File

@@ -373,7 +373,7 @@ abstract class EffectQuantum {
CallQuantum(EKey key, DataValue[] data, boolean isStatic) {
super((key.hashCode() * 31 + Arrays.hashCode(data)) * 31 + (isStatic ? 1 : 0));
this.key = key;
this.data = data;
this.data = data.length == 0 ? DataValue.EMPTY : data;
this.isStatic = isStatic;
}

View File

@@ -38,7 +38,7 @@ final class ELattice<T extends Enum<T>> {
class ResultUtil {
private static final EKey[] EMPTY_PRODUCT = new EKey[0];
private static final EKey[] EMPTY_PRODUCT = EKey.EMPTY_ARRAY;
private final ELattice<Value> lattice;
final Value top;
final Value bottom;