aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-02-19 07:51:35 +0100
committerBjörn Gustavsson <[email protected]>2016-02-23 09:16:12 +0100
commit8aa4ff517c3dcc119ca593616875195895301189 (patch)
treebac0046501d0c4e6696ad4243b4f7697861f75d2 /lib/compiler
parent48411ad12f4d730412895e90c188c2d8f7813ce5 (diff)
downloadotp-8aa4ff517c3dcc119ca593616875195895301189.tar.gz
otp-8aa4ff517c3dcc119ca593616875195895301189.tar.bz2
otp-8aa4ff517c3dcc119ca593616875195895301189.zip
sys_core_fold: Optimize clause/4
Save work the *extremely* common case that the guard is a literal.
Diffstat (limited to 'lib/compiler')
-rw-r--r--lib/compiler/src/sys_core_fold.erl10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index 43ce9a7172..b78507c47e 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -1081,12 +1081,16 @@ is_atom_or_var(_) -> false.
clause(#c_clause{pats=Ps0,guard=G0,body=B0}=Cl, Cexpr, Ctxt, Sub0) ->
{Ps1,Sub1} = pattern_list(Ps0, Sub0),
Sub2 = update_types(Cexpr, Ps1, Sub1),
- GSub = case {Cexpr,Ps1} of
- {#c_var{name='_'},_} ->
+ GSub = case {Cexpr,Ps1,G0} of
+ {_,_,#c_literal{}} ->
+ %% No need for substitution tricks when the guard
+ %% does not contain any variables.
+ Sub2;
+ {#c_var{name='_'},_,_} ->
%% In a 'receive', Cexpr is the variable '_', which represents the
%% message being matched. We must NOT do any extra substiutions.
Sub2;
- {#c_var{},[#c_var{}=Var]} ->
+ {#c_var{},[#c_var{}=Var],_} ->
%% The idea here is to optimize expressions such as
%%
%% case A of A -> ...