aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-04-13 17:00:44 +0200
committerBjörn Gustavsson <[email protected]>2015-04-22 10:12:33 +0200
commit3a9828cfe25971b5a6fb2f58f786127e63544bf1 (patch)
treef355b5b7fa68716dbfd70f26da452d4c410918f8
parent9bca15422cc76e2145e30b822ccc3599abec278a (diff)
downloadotp-3a9828cfe25971b5a6fb2f58f786127e63544bf1.tar.gz
otp-3a9828cfe25971b5a6fb2f58f786127e63544bf1.tar.bz2
otp-3a9828cfe25971b5a6fb2f58f786127e63544bf1.zip
v3_kernel: Optimize subst_vsub/3
Profiling shows that subst_vsub/3 dominates the running time. It is therefore worthwhile optimizing it.
-rw-r--r--lib/compiler/src/v3_kernel.erl23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/compiler/src/v3_kernel.erl b/lib/compiler/src/v3_kernel.erl
index 0ac1aaf158..7dff58582e 100644
--- a/lib/compiler/src/v3_kernel.erl
+++ b/lib/compiler/src/v3_kernel.erl
@@ -836,12 +836,23 @@ get_vsub(V, Vsub) ->
set_vsub(V, S, Vsub) ->
orddict:store(V, S, Vsub).
-subst_vsub(V, S, Vsub0) ->
- %% Fold chained substitutions.
- Vsub1 = orddict:map(fun (_, V1) when V1 =:= V -> S;
- (_, V1) -> V1
- end, Vsub0),
- orddict:store(V, S, Vsub1).
+subst_vsub(Key, New, [{K,Key}|Dict]) ->
+ %% Fold chained substitution.
+ [{K,New}|subst_vsub(Key, New, Dict)];
+subst_vsub(Key, New, [{K,_}|_]=Dict) when Key < K ->
+ %% Insert the new substitution here, and continue
+ %% look for chained substitutions.
+ [{Key,New}|subst_vsub_1(Key, New, Dict)];
+subst_vsub(Key, New, [{K,_}=E|Dict]) when Key > K ->
+ [E|subst_vsub(Key, New, Dict)];
+subst_vsub(Key, New, []) -> [{Key,New}].
+
+subst_vsub_1(V, S, [{K,V}|Dict]) ->
+ %% Fold chained substitution.
+ [{K,S}|subst_vsub_1(V, S, Dict)];
+subst_vsub_1(V, S, [E|Dict]) ->
+ [E|subst_vsub_1(V, S, Dict)];
+subst_vsub_1(_, _, []) -> [].
get_fsub(F, A, Fsub) ->
case orddict:find({F,A}, Fsub) of