Permalink
Browse files

compile all the way to a fun

  • Loading branch information...
1 parent 12f0a72 commit 0dce40dd545336566e4e614ea7914f487d66936a @mojombo committed Dec 24, 2009
Showing with 5 additions and 4 deletions.
  1. +1 −0 benchmarks/bench.erl
  2. +4 −4 mustache.erl
View
@@ -14,6 +14,7 @@ run() ->
T1 = erlang:now(),
Diff = timer:now_diff(T1, T0),
Mean = Diff / 100,
+ io:format("~nTotal time: ~.2fs~n", [Diff / 1000000]),
io:format("Mean render time: ~.2fms~n", [Mean / 1000]).
render(_CT, _Ctx, 0) ->
View
@@ -17,7 +17,9 @@ compile(Mod, File) ->
% io:format(CompiledTemplate ++ "~n", []),
{ok, Tokens, _} = erl_scan:string(CompiledTemplate),
{ok, [Form]} = erl_parse:parse_exprs(Tokens),
- Form.
+ Bindings = erl_eval:new_bindings(),
+ {value, Fun, _} = erl_eval:expr(Form, Bindings),
+ Fun.
render(Mod, File) when is_list(File) ->
render(Mod, File, dict:new());
@@ -29,9 +31,7 @@ render(Mod, File, Ctx) when is_list(File) ->
render(Mod, CompiledTemplate, Ctx);
render(Mod, CompiledTemplate, Ctx) ->
Ctx2 = dict:store('__mod__', Mod, Ctx),
- Bindings = erl_eval:new_bindings(),
- {value, Fun, _} = erl_eval:expr(CompiledTemplate, Bindings),
- lists:flatten(Fun(Ctx2)).
+ lists:flatten(CompiledTemplate(Ctx2)).
pre_compile(T, State) ->
SectionRE = "\{\{\#([^\}]*)}}\s*(.+?){{\/\\1\}\}\s*",

0 comments on commit 0dce40d

Please sign in to comment.