mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use ObjectLongHashMap to save memory
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<K> extends TObjectLongHashMap<K> {
|
||||
public ObjectLongHashMap(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
public ObjectLongHashMap(@NotNull TObjectHashingStrategy<K> strategy) {
|
||||
super(strategy);
|
||||
}
|
||||
|
||||
public ObjectLongHashMap(int initialCapacity, @NotNull TObjectHashingStrategy<K> strategy) {
|
||||
super(initialCapacity, strategy);
|
||||
}
|
||||
|
||||
public ObjectLongHashMap() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final long get(K key) {
|
||||
int index = index(key);
|
||||
return index < 0 ? -1 : _values[index];
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -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<Pair<VirtualFile, Integer>, Set<XValueNodeImpl>> map = project.getUserData(XVariablesView.DEBUG_VARIABLES);
|
||||
final Map<VirtualFile, Long> timestamps = project.getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS);
|
||||
final ObjectLongHashMap<VirtualFile> 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<XValueNodeImpl> 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;
|
||||
|
||||
@@ -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<Map<Pair<VirtualFile, Integer>, Set<XValueNodeImpl>>> DEBUG_VARIABLES = Key.create("debug.variables");
|
||||
public static final Key<Map<VirtualFile, Long>> DEBUG_VARIABLES_TIMESTAMPS = Key.create("debug.variables.timestamps");
|
||||
public static final Key<ObjectLongHashMap<VirtualFile>> DEBUG_VARIABLES_TIMESTAMPS = Key.create("debug.variables.timestamps");
|
||||
|
||||
public XVariablesView(@NotNull XDebugSessionImpl session) {
|
||||
super(session.getProject(), session.getDebugProcess().getEditorsProvider(), session.getValueMarkers());
|
||||
|
||||
+4
-3
@@ -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<Pair<VirtualFile, Integer>, Set<XValueNodeImpl>>());
|
||||
project.putUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS, new HashMap<VirtualFile, Long>());
|
||||
project.putUserData(XVariablesView.DEBUG_VARIABLES, new THashMap<Pair<VirtualFile, Integer>, Set<XValueNodeImpl>>());
|
||||
project.putUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS, new ObjectLongHashMap<VirtualFile>());
|
||||
Object newEqualityObject = stackFrame.getEqualityObject();
|
||||
if (myFrameEqualityObject != null && newEqualityObject != null && myFrameEqualityObject.equals(newEqualityObject)
|
||||
&& myTreeState != null) {
|
||||
|
||||
+3
-2
@@ -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<XValue> implements XValu
|
||||
@Override
|
||||
public void computed(@NotNull VirtualFile file, @NotNull Document document, int line) {
|
||||
final Map<Pair<VirtualFile, Integer>, Set<XValueNodeImpl>> map = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES);
|
||||
final Map<VirtualFile, Long> timestamps = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS);
|
||||
final TObjectLongHashMap<VirtualFile> timestamps = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS);
|
||||
if (map == null || timestamps == null) {
|
||||
return;
|
||||
}
|
||||
@@ -169,7 +170,7 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
|
||||
public void setSourcePosition(@Nullable XSourcePosition sourcePosition) {
|
||||
final Map<Pair<VirtualFile, Integer>, Set<XValueNodeImpl>> map =
|
||||
myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES);
|
||||
final Map<VirtualFile, Long> timestamps = myTree.getProject().getUserData(XVariablesView.DEBUG_VARIABLES_TIMESTAMPS);
|
||||
final TObjectLongHashMap<VirtualFile> 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;
|
||||
|
||||
Reference in New Issue
Block a user