ribesg
04/20/2018, 10:07 PMcache.entries.removeAll {
val res = now - it.value.first > duration
if (res) <http://log.info|log.info>("Removing value in cache $name for key ${it.key}")
res
}
orangy
04/20/2018, 10:15 PMremoveAll
is a Java method, then SAM conversion will create instance each time (I think)ribesg
04/20/2018, 10:20 PMorangy
04/20/2018, 10:29 PMnow
is what makes it create a captureribesg
04/20/2018, 10:32 PMopen fun clear() {
val now = now
cache.entries.removeAll {
val res = now - it.value.first > duration
if (res) <http://log.info|log.info>("Removing value in cache $name for key ${it.key}")
res
}
errors.entries.removeAll {
val res = now - it.value.first > errorDuration
if (res) <http://log.info|log.info>("Removing error in cache $name for key ${it.key}")
res
}
}
orangy
04/20/2018, 10:42 PMclear
should create just two instances of lambdasribesg
04/20/2018, 10:51 PMorangy
04/20/2018, 10:58 PMnow
into a local variable and use it in lambdas. They have to create an instance and capture value in an anonymous class so it is available to the code inside lambda.AnonymousClass(val now) : Predicate<Boolean> { override fun invoke() { … you code here … } }
filterInPlace
(private in stdlib), make it inline, and give it a good name.