From a55f8ac6318b16bdf306d601e3d1022ccb5e4c46 Mon Sep 17 00:00:00 2001 From: Jason Koch Date: Sat, 10 Aug 2024 23:06:49 -0700 Subject: [PATCH] perf: use Set instead of List to track subClasses fixes #59 --- .../src/org/eclipse/mat/parser/model/ClassImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/model/ClassImpl.java b/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/model/ClassImpl.java index 0870c6c8e..8c59f4517 100644 --- a/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/model/ClassImpl.java +++ b/plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/model/ClassImpl.java @@ -19,8 +19,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicLongFieldUpdater; @@ -67,7 +69,7 @@ public class ClassImpl extends AbstractObjectImpl implements IClass, Comparable< protected volatile long totalSize; protected boolean isArrayType; - private List subClasses; + private Set subClasses; private Serializable cacheEntry; @@ -392,14 +394,14 @@ void removeInstanceBulk(int instanceCount, long heapSize) @SuppressWarnings("unchecked") public List getSubclasses() { - return subClasses != null ? subClasses : Collections.EMPTY_LIST; + return (subClasses == null) ? Collections.emptyList() : new ArrayList<>(subClasses); } @Override public List getAllSubclasses() { if (subClasses == null || subClasses.isEmpty()) - return new ArrayList(); + return Collections.emptyList(); List answer = new ArrayList(subClasses.size() * 2); answer.addAll(this.subClasses); @@ -453,7 +455,7 @@ public int getClassLoaderId() public void addSubClass(ClassImpl clazz) { if (subClasses == null) - subClasses = new ArrayList(); + subClasses = new LinkedHashSet(); subClasses.add(clazz); }