diff options
author | scgilardi <scgilardi@gmail.com> | 2008-12-04 22:55:28 +0000 |
---|---|---|
committer | scgilardi <scgilardi@gmail.com> | 2008-12-04 22:55:28 +0000 |
commit | 6e81055fa52b1e64e951c34ef9f4b363bd7e0139 (patch) | |
tree | 6d8c4cceddb876eacfe6f8d3c9a19978adb52037 /src/clojure/contrib/memoize.clj | |
parent | bc6540e0e5e307b0b04b0f66d10289474a79cd70 (diff) |
memoize: change from ref to atom for cache
Diffstat (limited to 'src/clojure/contrib/memoize.clj')
-rw-r--r-- | src/clojure/contrib/memoize.clj | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/clojure/contrib/memoize.clj b/src/clojure/contrib/memoize.clj index 558106c6..7becb30b 100644 --- a/src/clojure/contrib/memoize.clj +++ b/src/clojure/contrib/memoize.clj @@ -22,10 +22,9 @@ to results and, when calls with the same arguments are repeated often, has higher performance at the expense of higher memory use." [function] - (let [cache (ref {})] + (let [cache (atom {})] (fn [& args] (or (@cache args) (let [result (apply function args)] - (dosync - (commute cache assoc args result)) + (swap! cache assoc args result) result))))) |