Просмотр исходного кода

wrap block.super contents in a fun.

So if block.super is never referenced, the contents doesn't have to
get built, which ought to save quite a bit for larger more complicated
blocks.

Also, ignore all "a term is constructed, but never used" warnings in
compiled test templates.
Andreas Stenius 10 лет назад
Родитель
Сommit
75dbb0090a
3 измененных файлов с 6 добавлено и 4 удалено
  1. 1 1
      src/erlydtl_beam_compiler.erl
  2. 3 1
      test/erlydtl_eunit_testrunner.erl
  3. 2 2
      test/erlydtl_test_defs.erl

+ 1 - 1
src/erlydtl_beam_compiler.erl

@@ -585,7 +585,7 @@ body_ast(DjangoParseTree, BodyScope, TreeWalker) ->
                         lists:foldr(
                           fun ({ChildFile, ChildPos, ChildBlock}, {{SuperAst, SuperInfo}, AccTW}) ->
                                   BlockScope = create_scope(
-                                                 [{block, ?Q("[{super, _@SuperAst}]"), safe}],
+                                                 [{block, ?Q("fun (super) -> _@SuperAst; (_) -> [] end"), safe}],
                                                  ChildPos, ChildFile, AccTW),
                                   {{BlockAst, BlockInfo}, BlockTW} = body_ast(ChildBlock, BlockScope, AccTW),
                                   {{BlockAst, merge_info(SuperInfo, BlockInfo)}, BlockTW}

+ 3 - 1
test/erlydtl_eunit_testrunner.erl

@@ -58,8 +58,10 @@ run_compile(T) ->
            T#test.module,
            compile_opts(T))
     of
-        {ok, M, W} ->
+        {ok, M, W0} ->
             ?assertEqual(T#test.module, M),
+            %% ignore useless_building warnings on line 588 in anonymous files
+            W = W0 -- [{[], [{588, sys_core_fold, useless_building}]}],
             ?assertEqual(T#test.warnings, W);
         {error, E, W} ->
             ?assertEqual(T#test.errors, E),

+ 2 - 2
test/erlydtl_test_defs.erl

@@ -1897,8 +1897,8 @@ setup_compile("var_preset") ->
     CompileVars = [{preset_var1, "preset-var1"}, {preset_var2, "preset-var2"}],
     {ok, [CompileVars]};
 setup_compile("extends_for") ->
-	CompileVars = [{veggie_list, ["broccoli", "beans", "peas", "carrots"]}],
-	{ok, [CompileVars]};
+    CompileVars = [{veggie_list, ["broccoli", "beans", "peas", "carrots"]}],
+    {ok, [CompileVars]};
 setup_compile("extends2") ->
     File = template_file(input, "extends2"),
     Error = {none, erlydtl_beam_compiler, unexpected_extends_tag},