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

Alex S. alex0player@REDACTED
Wed Aug 2 22:45:12 CEST 2017


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 <aschultz@REDACTED>:

> 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: as@REDACTED
> 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:  info@REDACTED
> GERMANY                             web:    http://www.travelping.com
>
> Company Registration: Amtsgericht Stendal        Reg No.:   HRB 10578
> Geschaeftsfuehrer: Holger Winkelmann          VAT ID No.: DE236673780
> ---------------------------------------------------------------------
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170802/a1bb1013/attachment.htm>


More information about the erlang-questions mailing list