Commit 26111a36 authored by Noric Couderc's avatar Noric Couderc

Simplified function

Removed relying of map's mutability
parent 2b2eefcd
......@@ -93,21 +93,15 @@ class TraceLoader {
return traces
}
fun removeDuplicates(traceData : List<TraceData>): List<AggregatedTraceData> {
val duplicateCounts = traceData.groupBy { Triple(it.location, it.target_type, it.methods) }
.mapValues { it.value.size }
.toMutableMap()
var result = mutableListOf<AggregatedTraceData>()
for (t in traceData) {
val key = Triple(t.location, t.target_type, t.methods)
val count = duplicateCounts[key]
// If we haven't seen it before
if (count != null) {
result.add(AggregatedTraceData(t.location, t.target_type, t.methods, count))
duplicateCounts.remove(key)
} // Otherwise, we ignore this duplicate
for (kvp in duplicateCounts) {
val key = kvp.key
val count = kvp.value
result.add(AggregatedTraceData(key.first, key.second, key.third, count))
}
return result
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment