File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
src/main/scala/com/gilt/handlebars Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -215,11 +215,15 @@ class HandlebarsVisitor[T](context: Context[T],
215215 * A wrapper around the literal context as referenced from templates.
216216 */
217217trait Context [+ T ] {
218+ import java .lang .reflect .Method
219+
218220 private val logger : Logger = LoggerFactory .getLogger(getClass)
219221
220222 // the wrapped context with which user code deals
221223 val context : T
222224
225+ val methodsCache : Map [String , Method ] = (context.getClass.getMethods map { m => (m.getName + m.getParameterTypes.length, m) }).toMap
226+
223227 // Option, since the root context does
224228 // not have a parent, but all others do
225229 val parent : Option [Context [Any ]]
@@ -242,11 +246,7 @@ trait Context[+T] {
242246 }
243247 }
244248
245- def getMethod [A ](name : String , args : List [A ] = Nil ) = {
246- context.getClass.getMethods find { method =>
247- method.getName == name && method.getParameterTypes.length == args.length
248- }
249- }
249+ def getMethod [A ](name : String , args : List [A ] = Nil ) = methodsCache.get(name + args.length)
250250
251251 // these are lazy vals instead of functions
252252 // since they don't take up too much space
You can’t perform that action at this time.
0 commit comments