From 1a46db7c1dfa9a9f0c20756773ccd17fef7dadfe Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Thu, 2 Feb 2023 12:31:48 +0400 Subject: [PATCH] IDEA-311645 Interned strings in the PathElement GitOrigin-RevId: 4bc245050c9d32a1363fc1e3bc99b2da646aeabb --- .../intellij/ide/util/treeView/TreeState.java | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java index dc9cd29a521f..1506440e613c 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java @@ -14,6 +14,7 @@ import com.intellij.ui.tree.TreeVisitor; import com.intellij.util.ExceptionUtil; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.Interner; import com.intellij.util.ui.tree.TreeUtil; import com.intellij.util.xmlb.XmlSerializer; import com.intellij.util.xmlb.annotations.Attribute; @@ -44,6 +45,8 @@ import java.util.function.Consumer; * @see #applyTo(JTree, Object) */ public final class TreeState implements JDOMExternalizable { + private static final Interner INTERNER = Interner.createStringInterner(); + private static final Logger LOG = Logger.getInstance(TreeState.class); public static final Key> CALLBACK = Key.create("Callback"); @@ -57,10 +60,8 @@ public final class TreeState implements JDOMExternalizable { @Tag("item") static final class PathElement { - @Attribute("name") - public String id; - @Attribute("type") - public String type; + String id; + String type; transient Object userObject; transient final int index; @@ -70,11 +71,11 @@ public final class TreeState implements JDOMExternalizable { } PathElement(String itemId, String itemType, int itemIndex, Object userObject) { - id = itemId; - type = itemType; + setId(itemId); + setType(itemType); index = itemIndex; - this.userObject = userObject; + this.userObject = userObject instanceof String stringObject ? INTERNER.intern(stringObject) : userObject; } @Override @@ -94,6 +95,26 @@ public final class TreeState implements JDOMExternalizable { return Objects.equals(id, calcId(userObject)) && Objects.equals(type, calcType(userObject)) ? Match.ID_TYPE : null; } + + @Attribute("name") + public void setId(String id) { + this.id = id == null ? null : INTERNER.intern(id); + } + + @Attribute("name") + public String getId() { + return id; + } + + @Attribute("type") + public void setType(String type) { + this.type = type == null ? null : INTERNER.intern(type); + } + + @Attribute("type") + public String getType() { + return type; + } } @XCollection(style = XCollection.Style.v2)