Subject: Re: [erlang-questions] binary match vs. is_binary
in optimization



t1 doesn't extract a sub-binary from your binary, so there's nothing to optimize.
2017-08-02 19:35 GMT+03:00 Andreas Schultz <[email protected]>:
Hi,

Can someone explain why the binary optimization treats a is_binary()
guard different that an binary match?

I the attached test code, I get a:

> test.erl:7: Warning: NOT OPTIMIZED: called function t1/1 does not begin with a suitable binary matching instruction

and a

> test.erl:14: Warning: OPTIMIZED: creation of sub binary delayed

for the second function. IMHO both should be identical, but apparently they are not.

Many thanks,
Andreas

Test code:

-module(test).

-compile([bin_opt_info]).

-export([do/1]).

do(<<Bin/binary>>) ->
    t1(Bin),
    t3(Bin).

t1(Bin) when is_binary(Bin) ->
    test(Bin, []).

t3(<<Bin/binary>>) ->
    test(Bin, []).

test(<<X:4/integer, _/binary>>, _) ->
    X.
--
Dipl.-Inform. Andreas Schultz

email: [email protected]
phone: +49-391-819099-224

----------------------- enabling your networks ----------------------

Travelping GmbH                     phone:  +49-391-81 90 99 0
Roentgenstr.  13                    fax:    +49-391-81 90 99 299
39108 Magdeburg                     email:  [email protected]
GERMANY                             web:   
www.travelping.com" rel="noreferrer" target="_blank">http://www.travelping.com


Company Registration: Amtsgericht Stendal        Reg No.:   HRB 10578
Geschaeftsfuehrer: Holger Winkelmann          VAT ID No.: DE236673780
---------------------------------------------------------------------
_______________________________________________
erlang-questions mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-questions



Programming list archiving by: Enterprise Git Hosting