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 #473 from wiwa/f/rsccompat-perf
Cache member lookup in RscCompat Scopes
- Loading branch information
Showing
3 changed files
with
29 additions
and
1 deletion.
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
14 changes: 14 additions & 0 deletions
14
scalafix/rules/src/main/scala/rsc/rules/util/MemoizeUtil.scala
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,14 @@ | ||
package rsc.rules.util | ||
|
||
trait MemoizeUtil { | ||
|
||
/** | ||
* Memoize the results of a function call to prevent repeated calls | ||
*/ | ||
def memoize[I, O](f: I => O): I => O = { | ||
val _cache = new java.util.HashMap[I, O] | ||
|
||
key => | ||
_cache.computeIfAbsent(key, _ => f(key)) | ||
} | ||
} |
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,3 @@ | ||
package rsc.rules | ||
|
||
package object util extends MemoizeUtil |