@@ -148,7 +148,13 @@ public IClassHierarchy getClassHierarchy() {
148
148
149
149
private final Map <CallSiteReference , Set <IMethod >> targetCache = HashMapFactory .make ();
150
150
151
- private Iterator <IMethod > getPossibleTargets (CallSiteReference site ) {
151
+ /**
152
+ * Gets the possible targets of a call site, caching the result if it has not been computed.
153
+ *
154
+ * @param site the call site
155
+ * @return an iterator of possible targets
156
+ */
157
+ private Iterator <IMethod > getOrUpdatePossibleTargets (CallSiteReference site ) {
152
158
Set <IMethod > result = targetCache .get (site );
153
159
if (result == null ) {
154
160
if (site .isDispatch ()) {
@@ -166,11 +172,25 @@ private Iterator<IMethod> getPossibleTargets(CallSiteReference site) {
166
172
return result .iterator ();
167
173
}
168
174
175
+ /**
176
+ * Gets the possible targets of a call site from the cache.
177
+ *
178
+ * @param site the call site
179
+ * @return an iterator of possible targets
180
+ */
181
+ private Iterator <IMethod > getPossibleTargetsFromCache (CallSiteReference site ) {
182
+ Set <IMethod > result = targetCache .get (site );
183
+ if (result == null ) {
184
+ return Collections .emptyIterator ();
185
+ }
186
+ return result .iterator ();
187
+ }
188
+
169
189
@ Override
170
190
public Set <CGNode > getPossibleTargets (CGNode node , CallSiteReference site ) {
171
191
return Iterator2Collection .toSet (
172
192
new MapIterator <>(
173
- new FilterIterator <>(getPossibleTargets (site ), this ::isRelevantMethod ),
193
+ new FilterIterator <>(getPossibleTargetsFromCache (site ), this ::isRelevantMethod ),
174
194
object -> {
175
195
try {
176
196
return findOrCreateNode (object , Everywhere .EVERYWHERE );
@@ -183,7 +203,7 @@ public Set<CGNode> getPossibleTargets(CGNode node, CallSiteReference site) {
183
203
184
204
@ Override
185
205
public int getNumberOfTargets (CGNode node , CallSiteReference site ) {
186
- return IteratorUtil .count (getPossibleTargets (site ));
206
+ return IteratorUtil .count (getPossibleTargetsFromCache (site ));
187
207
}
188
208
189
209
@ Override
@@ -259,7 +279,7 @@ private void closure() throws CancelException {
259
279
while (!newNodes .isEmpty ()) {
260
280
CGNode n = newNodes .pop ();
261
281
for (CallSiteReference site : Iterator2Iterable .make (n .iterateCallSites ())) {
262
- Iterator <IMethod > methods = getPossibleTargets (site );
282
+ Iterator <IMethod > methods = getOrUpdatePossibleTargets (site );
263
283
while (methods .hasNext ()) {
264
284
IMethod target = methods .next ();
265
285
if (isRelevantMethod (target )) {
0 commit comments