billrobertson42 / mustache.clojure

Glue code to allow mustache.java to work better with Clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion to avoid repeating `compile`

serioga opened this issue · comments

Looks like it is better move .compile out of (fn) scope to avoid this call on every render.
This call is quite fast but useless.

(fn [data]
(let [^MustacheFactory template-factory @mustache-factory
^Mustache template (.compile template-factory template-name)
^StringWriter buffer (StringWriter.)]
(.execute template buffer data)
(.toString buffer)))
(fn [data]
(let [^MustacheFactory template-factory mustache-factory
^Mustache template (.compile template-factory template-name)
^StringWriter buffer (StringWriter.)]
(.execute template buffer data)
(.toString buffer)))))

At first glance, I think you're right. While the call may be fast, it probably makes work for the garbage collector.

It has been a long time since I've looked at this code though. So I would like to take a look at things and make sure that this is right.