WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c72f843

Browse files
authored
Merge pull request soot-oss#2192 from MarcMil/improve
UnitGraph Preds: Faster for the common case (avoid allocating a full ArrayList)
2 parents 6a3e6e6 + 07c35d5 commit c72f843

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main/java/soot/toolkits/graph/UnitGraph.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,17 @@ protected void buildUnexceptionalEdges(Map<Unit, List<Unit>> unitToSuccs, Map<Un
107107

108108
List<Unit> preds = unitToPreds.get(nextUnit);
109109
if (preds == null) {
110-
preds = new ArrayList<Unit>();
111-
unitToPreds.put(nextUnit, preds);
110+
// Most units only have one predecessor.
111+
unitToPreds.put(nextUnit, Collections.singletonList(currentUnit));
112+
} else {
113+
if (!(preds instanceof ArrayList)) {
114+
List<Unit> npreds = new ArrayList<>(preds.size() + 1);
115+
npreds.addAll(preds);
116+
preds = npreds;
117+
unitToPreds.put(nextUnit, npreds);
118+
}
119+
preds.add(currentUnit);
112120
}
113-
preds.add(currentUnit);
114121
}
115122
}
116123

@@ -138,6 +145,11 @@ protected void buildUnexceptionalEdges(Map<Unit, List<Unit>> unitToSuccs, Map<Un
138145
if (preds == null) {
139146
preds = new ArrayList<Unit>();
140147
unitToPreds.put(target, preds);
148+
} else if (!(preds instanceof ArrayList)) {
149+
List<Unit> npreds = new ArrayList<>(preds.size() + 1);
150+
npreds.addAll(preds);
151+
preds = npreds;
152+
unitToPreds.put(target, preds);
141153
}
142154
preds.add(currentUnit);
143155
}

0 commit comments

Comments
 (0)