Skip to content

Commit

Permalink
Refactor memoization for easier benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
pbiggar committed Jan 4, 2013
1 parent 6e32fce commit a6ac981
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dieter-core/src/dieter/asset.clj
Expand Up @@ -34,7 +34,7 @@ Contents can be a String, StringBuilder, or byte[]"))
saved-content

;; compute new value and save it
(let [new-content (f)]
(let [new-content (f file)]
(dosync
(swap! memoized assoc filename {:content new-content
:timestamp (time/now)}))
Expand Down
12 changes: 7 additions & 5 deletions dieter-core/src/dieter/asset/coffeescript.clj
Expand Up @@ -6,12 +6,14 @@

(def pool (pools/make-pool))

(defn compile-coffeescript [file]
(run-compiler pool
["coffee-script.js" "coffee-wrapper.js"]
"compileCoffeeScript"
file))

(defn preprocess-coffeescript [file]
(asset/memoize-file file
#(run-compiler pool
["coffee-script.js" "coffee-wrapper.js"]
"compileCoffeeScript"
file)))
(asset/memoize-file file compile-coffeescript))

(defrecord Coffee [file]
dieter.asset.Asset
Expand Down
24 changes: 13 additions & 11 deletions dieter-core/src/dieter/asset/hamlcoffee.clj
Expand Up @@ -6,18 +6,20 @@

(def pool (pools/make-pool))

(defn compile-coffeescript [file]
(run-compiler pool
["coffee-script.js"
;; imported direct from https://raw.github.com/netzpirat/haml-coffee/master/dist/compiler/hamlcoffee.js
"hamlcoffee.js"
"haml_coffee_assets-rhino-fix.js"
;; imported direct from https://raw.github.com/netzpirat/haml_coffee_assets/master/lib/js/haml_coffee_assets.js
"haml_coffee_assets.js"
"hamlcoffee-wrapper.js"]
"compileHamlCoffee"
file))

(defn preprocess-hamlcoffee [file]
(asset/memoize-file file
#(run-compiler pool
["coffee-script.js"
;; imported direct from https://raw.github.com/netzpirat/haml-coffee/master/dist/compiler/hamlcoffee.js
"hamlcoffee.js"
"haml_coffee_assets-rhino-fix.js"
;; imported direct from https://raw.github.com/netzpirat/haml_coffee_assets/master/lib/js/haml_coffee_assets.js
"haml_coffee_assets.js"
"hamlcoffee-wrapper.js"]
"compileHamlCoffee"
file)))
(asset/memoize-file file compile-coffeescript))

(defrecord HamlCoffee [file]
dieter.asset.Asset
Expand Down

0 comments on commit a6ac981

Please sign in to comment.