aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2010-03-12 09:12:05 +0100
committerBjörn Gustavsson <[email protected]>2010-06-02 11:51:25 +0200
commit1858cb81391d2bce29b4b7620574ca60128cebf7 (patch)
tree1053271b8901a91c99c1884702908a1f33202896 /lib/stdlib/test
parent012e340d83e34200705200c5fafd55ee990c1795 (diff)
downloadotp-1858cb81391d2bce29b4b7620574ca60128cebf7.tar.gz
otp-1858cb81391d2bce29b4b7620574ca60128cebf7.tar.bz2
otp-1858cb81391d2bce29b4b7620574ca60128cebf7.zip
erl_expand_records: Replace is_record() with matching
The compiler currently generates better code for: f(#r1{}) -> r1; f(#r2{}) -> r2; f(#r3{}) -> r3. than for: g(X) when is_record(X, r1) -> r1; g(X) when is_record(X, r2) -> r2; g(X) when is_record(X, r3) -> r3. The compiler generates good code for pattern matching (as in f/1), but in g/1 there are no patterns to match, and the clause to be executed must be chosen by evaluating the guards sequentially until one succeeds. Make the compiler generate better code by replacing calls to is_record() with matching in the function head (basically, g/1 will automatically be rewritten to do pattern matching as in f/1). Note that this rewrite will also benefit code such as: h(X) when X#r1.a =:= 1 -> ok. because it would have been rewritten to: h(X) when (is_record(X, r1, 3) orelse fail) and (element(2, X) =:= 1) -> ok. which in turn will be rewritten to: h({r1,_,_}=X) when (true orelse fail) and (element(2, X) =:= 1) -> ok. (That will be further simplified in later compiler passes.)
Diffstat (limited to 'lib/stdlib/test')
0 files changed, 0 insertions, 0 deletions