-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from bjaglin/classloading
Fix 0.9.18 caching/performance regressions
- Loading branch information
Showing
2 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package scalafix.internal.sbt | ||
|
||
import java.{util => ju} | ||
|
||
/** A basic thread-safe cache without any eviction. */ | ||
class BlockingCache[K, V] { | ||
|
||
// Number of keys is expected to be very small so the global lock should not be a bottleneck | ||
private val underlying = ju.Collections.synchronizedMap(new ju.HashMap[K, V]) | ||
|
||
/** | ||
* @param value By-name parameter evaluated when the key if missing. Value computation is guaranteed | ||
* to be called only once per key across all invocations. | ||
*/ | ||
def getOrElseUpdate(key: K, value: => V): V = | ||
underlying.computeIfAbsent( | ||
key, | ||
new ju.function.Function[K, V] { | ||
override def apply(k: K): V = value | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters