Skip to content

Commit

Permalink
Have a more robust cache that support concurrent access and writes in @…
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Oct 5, 2024
1 parent f02a0fb commit fc587f4
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/scala/steps/annotation/memoize.scala
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package steps.annotation
import scala.annotation.{experimental, MacroAnnotation}
import scala.quoted.*
import scala.collection.mutable.Map
import scala.collection.concurrent.TrieMap

@experimental
class memoize extends MacroAnnotation:
@@ -30,7 +31,7 @@ class memoize extends MacroAnnotation:
val symbol = Symbol.newVal(Symbol.spliceOwner, name, TypeRepr.of[Map[K, V]], Flags.Private, Symbol.spliceOwner)
val rhs =
given Quotes = symbol.asQuotes
'{ Map.empty[K, V] }.asTerm
'{ TrieMap.empty[K, V] }.asTerm
end rhs
ValDef(symbol, Some(rhs))
end buildCache
2 changes: 1 addition & 1 deletion src/test/scala/steps/annotation/memoize.scala
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package steps.annotation
import scala.annotation.experimental

@experimental
class FibonacciMemoize extends munit.FunSuite:
final class FibonacciMemoize extends munit.FunSuite:

@memoize
def fib(n: Int): Int =

0 comments on commit fc587f4

Please sign in to comment.