From 825b2d3ca3edc91a3b0b61d9c420358f5028f737 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 28 Nov 2014 16:58:47 +0100 Subject: [PATCH] use ObjectLongHashMap to save memory --- .../util/containers/ObjectIntHashMap.java | 15 ++++++ .../util/containers/ObjectLongHashMap.java | 47 +++++++++++++++++++ .../evaluate/XDebuggerEditorLinePainter.java | 11 +++-- .../xdebugger/impl/frame/XVariablesView.java | 3 +- .../impl/frame/XVariablesViewBase.java | 7 +-- .../impl/ui/tree/nodes/XValueNodeImpl.java | 5 +- 6 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 platform/util/src/com/intellij/util/containers/ObjectLongHashMap.java diff --git a/platform/util/src/com/intellij/util/containers/ObjectIntHashMap.java b/platform/util/src/com/intellij/util/containers/ObjectIntHashMap.java index e1f7159fc98c..6584522b8c8c 100644 --- a/platform/util/src/com/intellij/util/containers/ObjectIntHashMap.java +++ b/platform/util/src/com/intellij/util/containers/ObjectIntHashMap.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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 com.intellij.util.containers; import gnu.trove.TObjectHashingStrategy; diff --git a/platform/util/src/com/intellij/util/containers/ObjectLongHashMap.java b/platform/util/src/com/intellij/util/containers/ObjectLongHashMap.java new file mode 100644 index 000000000000..2f783cb98efb --- /dev/null +++ b/platform/util/src/com/intellij/util/containers/ObjectLongHashMap.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 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 com.intellij.util.containers; + +import gnu.trove.TObjectHashingStrategy; +import gnu.trove.TObjectLongHashMap; +import org.jetbrains.annotations.NotNull; + +/** + * return -1 instead of 0 if no such mapping exists + */ +public class ObjectLongHashMap extends TObjectLongHashMap { + public ObjectLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + public ObjectLongHashMap(@NotNull TObjectHashingStrategy strategy) { + super(strategy); + } + + public ObjectLongHashMap(int initialCapacity, @NotNull TObjectHashingStrategy strategy) { + super(initialCapacity, strategy); + } + + public ObjectLongHashMap() { + super(); + } + + @Override + public final long get(K key) { + int index = index(key); + return index < 0 ? -1 : _values[index]; + } +} \ No newline at end of file diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XDebuggerEditorLinePainter.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XDebuggerEditorLinePainter.java index 3f124d04bc7c..047cbb1831b2 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XDebuggerEditorLinePainter.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/XDebuggerEditorLinePainter.java @@ -31,6 +31,7 @@ import com.intellij.ui.JBColor; import com.intellij.ui.SimpleColoredText; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.NotNullProducer; +import com.intellij.util.containers.ObjectLongHashMap; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.frame.presentation.XValuePresentation; @@ -57,7 +58,7 @@ public class XDebuggerEditorLinePainter extends EditorLinePainter { } final Map, Set> map = project.getUserData(XVariablesView.DEBUG_VARIABLES); - final Map timestamps = project.getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS); + final ObjectLongHashMap timestamps = project.getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS); final Document doc = FileDocumentManager.getInstance().getDocument(file); if (map == null || timestamps == null || doc == null) { @@ -70,7 +71,7 @@ public class XDebuggerEditorLinePainter extends EditorLinePainter { project.putUserData(CACHE, oldValues); } final Long timestamp = timestamps.get(file); - if (timestamp == null || timestamp < doc.getModificationStamp()) { + if (timestamp == -1 || timestamp < doc.getModificationStamp()) { return null; } Set values = map.get(Pair.create(file, lineNumber)); @@ -96,7 +97,7 @@ public class XDebuggerEditorLinePainter extends EditorLinePainter { } } } - catch (Exception e) { + catch (Exception ignored) { continue; } XDebugSession session = XDebugView.getSession(values.iterator().next().getTree()); @@ -191,8 +192,8 @@ public class XDebuggerEditorLinePainter extends EditorLinePainter { } static class Variable { - private int lineNumber; - private String name; + private final int lineNumber; + private final String name; public Variable(String name, int lineNumber) { this.lineNumber = lineNumber; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java index ea53645b57e5..16a1ce54d933 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java @@ -18,6 +18,7 @@ package com.intellij.xdebugger.impl.frame; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.ObjectLongHashMap; import com.intellij.xdebugger.XDebugProcess; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.frame.XStackFrame; @@ -37,7 +38,7 @@ import static com.intellij.xdebugger.impl.ui.tree.nodes.MessageTreeNode.createIn */ public class XVariablesView extends XVariablesViewBase { public static final Key, Set>> DEBUG_VARIABLES = Key.create("debug.variables"); - public static final Key> DEBUG_VARIABLES_TIMESTAMPS = Key.create("debug.variables.timestamps"); + public static final Key> DEBUG_VARIABLES_TIMESTAMPS = Key.create("debug.variables.timestamps"); public XVariablesView(@NotNull XDebugSessionImpl session) { super(session.getProject(), session.getDebugProcess().getEditorsProvider(), session.getValueMarkers()); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesViewBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesViewBase.java index e188c7df9d84..df36a51f3e45 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesViewBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesViewBase.java @@ -32,6 +32,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.ObjectLongHashMap; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XDebuggerBundle; import com.intellij.xdebugger.XSourcePosition; @@ -50,12 +51,12 @@ import com.intellij.xdebugger.impl.ui.tree.XDebuggerTreeState; import com.intellij.xdebugger.impl.ui.tree.nodes.XEvaluationCallbackBase; import com.intellij.xdebugger.impl.ui.tree.nodes.XStackFrameNode; import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl; +import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.HashMap; import java.util.Set; /** @@ -79,8 +80,8 @@ public abstract class XVariablesViewBase extends XDebugView { tree.setSourcePosition(position); tree.setRoot(new XStackFrameNode(tree, stackFrame), false); final Project project = tree.getProject(); - project.putUserData(XVariablesView.DEBUG_VARIABLES, new HashMap, Set>()); - project.putUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS, new HashMap()); + project.putUserData(XVariablesView.DEBUG_VARIABLES, new THashMap, Set>()); + project.putUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS, new ObjectLongHashMap()); Object newEqualityObject = stackFrame.getEqualityObject(); if (myFrameEqualityObject != null && newEqualityObject != null && myFrameEqualityObject.equals(newEqualityObject) && myTreeState != null) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java index 585a80a574bc..9e25d5bd8471 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java @@ -39,6 +39,7 @@ import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants; import com.intellij.xdebugger.impl.ui.tree.ValueMarkup; import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree; +import gnu.trove.TObjectLongHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -146,7 +147,7 @@ public class XValueNodeImpl extends XValueContainerNode implements XValu @Override public void computed(@NotNull VirtualFile file, @NotNull Document document, int line) { final Map, Set> map = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES); - final Map timestamps = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS); + final TObjectLongHashMap timestamps = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS); if (map == null || timestamps == null) { return; } @@ -169,7 +170,7 @@ public class XValueNodeImpl extends XValueContainerNode implements XValu public void setSourcePosition(@Nullable XSourcePosition sourcePosition) { final Map, Set> map = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES); - final Map timestamps = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS); + final TObjectLongHashMap timestamps = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS); if (map == null || timestamps == null || sourcePosition == null) return; VirtualFile file = sourcePosition.getFile(); if (!Comparing.equal(debuggerPosition.getFile(), sourcePosition.getFile())) return;