Given a List<T> I want compute a Map<T, Integer> where each entry in the
map is the # of occurrences of that object in the list. It seems to me the
idiomatic way to do this is
Map<T, Integer> listToMultiplicies(List<T> list) { list.collectEntries{ [it,
list.count(it)]} }
which works. As does this
Map<T, Integer> listToMultiplicies(List<T> list) {
Map<T, Integer> result = [:]
Integer c
list.each {
result[it] = (null != (c = result[it])) ? c + 1 : 1
}
result
}
The issue is that (even when CompileStatic'd) the idiomatic way is *orders
of magnitude* slower than the 'Groovy as Java' way. Am I missing something
obvious here ??
Alan
--
View this message in context:
http://groovy.329449.n5.nabble.com/Performance-conundrum-tp5738144.html
Sent from the Groovy Users mailing list archive at Nabble.com.