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

Andreas Schultz aschultz@REDACTED
Wed Aug 2 18:35:19 CEST 2017


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,

Test code:




do(<<Bin/binary>>) ->

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

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

test(<<X:4/integer, _/binary>>, _) ->
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

More information about the erlang-questions mailing list