@@ -165,7 +165,7 @@ class ReachingDefTransferFunction(flowGraph: ReachingDefFlowGraph)
165
165
val gen : Map [StoredNode , mutable.BitSet ] =
166
166
initGen(method).withDefaultValue(mutable.BitSet ())
167
167
168
- val kill : Map [StoredNode , Set [ Definition ] ] =
168
+ val kill : Map [StoredNode , mutable. BitSet ] =
169
169
initKill(method, gen).withDefaultValue(mutable.BitSet ())
170
170
171
171
/** For a given flow graph node `n` and set of definitions, apply the transfer function to
@@ -226,8 +226,8 @@ class ReachingDefTransferFunction(flowGraph: ReachingDefFlowGraph)
226
226
*/
227
227
private def initKill (
228
228
method : Method ,
229
- gen : Map [StoredNode , Set [ Definition ] ]
230
- ): Map [StoredNode , Set [ Definition ] ] =
229
+ gen : Map [StoredNode , mutable. BitSet ]
230
+ ): Map [StoredNode , mutable. BitSet ] =
231
231
232
232
val allIdentifiers : Map [String , List [CfgNode ]] =
233
233
val results = mutable.Map .empty[String , List [CfgNode ]]
@@ -266,44 +266,45 @@ class ReachingDefTransferFunction(flowGraph: ReachingDefFlowGraph)
266
266
* gen(call).
267
267
*/
268
268
private def killsForGens (
269
- genOfCall : Set [ Definition ] ,
269
+ genOfCall : mutable. BitSet ,
270
270
allIdentifiers : Map [String , List [CfgNode ]],
271
271
allCalls : Map [String , List [Call ]]
272
- ): Set [ Definition ] =
272
+ ): mutable. BitSet =
273
273
274
- def definitionsOfSameVariable (definition : Definition ): Set [Definition ] =
274
+ def definitionsOfSameVariable (definition : Definition ): Iterator [Definition ] =
275
275
val definedNodes = flowGraph.numberToNode(definition) match
276
276
case param : MethodParameterIn =>
277
- allIdentifiers(param.name)
277
+ allIdentifiers(param.name).iterator
278
278
.filter(x => x.id != param.id)
279
279
case identifier : Identifier =>
280
- val sameIdentifiers = allIdentifiers(identifier.name)
280
+ val sameIdentifiers = allIdentifiers(identifier.name).iterator
281
281
.filter(x => x.id != identifier.id)
282
282
283
283
/** Killing an identifier should also kill field accesses on that identifier.
284
284
* For example, a reassignment `x = new Box()` should kill any previous calls
285
285
* to `x.value`, `x.length()`, etc.
286
286
*/
287
- val sameObjects : Iterable [Call ] = allCalls.values .flatten
287
+ val sameObjects : Iterator [Call ] = allCalls.valuesIterator .flatten
288
288
.filter(_.name == Operators .fieldAccess)
289
289
.filter(_.ast.isIdentifier.nameExact(identifier.name).nonEmpty)
290
290
291
291
sameIdentifiers ++ sameObjects
292
292
case call : Call =>
293
- allCalls(call.code)
293
+ allCalls(call.code).iterator
294
294
.filter(x => x.id != call.id)
295
- case _ => Set ()
295
+ case _ => Iterator .empty
296
296
definedNodes
297
297
// It can happen that the CFG is broken and contains isolated nodes,
298
298
// in which case they are not in `nodeToNumber`. Let's filter those.
299
299
.collect {
300
300
case x if nodeToNumber.contains(x) => Definition .fromNode(x, nodeToNumber)
301
- }.toSet
301
+ }
302
302
end definitionsOfSameVariable
303
303
304
- genOfCall.flatMap { definition =>
305
- definitionsOfSameVariable(definition)
306
- }
304
+ val res = mutable.BitSet ()
305
+ for definition <- genOfCall do
306
+ res.addAll(definitionsOfSameVariable(definition))
307
+ res
307
308
end killsForGens
308
309
end ReachingDefTransferFunction
309
310
0 commit comments