diff options
author | José Valim <[email protected]> | 2019-05-10 14:05:40 +0200 |
---|---|---|
committer | José Valim <[email protected]> | 2019-08-05 12:55:44 +0200 |
commit | 3ff0914b5625b8ef76e6ff5a2f2db1c563ebed3c (patch) | |
tree | f2b29365a2cdea8b0566f0acd7bea68b3a4da193 /lib/crypto/c_src/crypto.c | |
parent | c6d5af1054f8d555a69111f29b59d5485ef8e48f (diff) | |
download | otp-3ff0914b5625b8ef76e6ff5a2f2db1c563ebed3c.tar.gz otp-3ff0914b5625b8ef76e6ff5a2f2db1c563ebed3c.tar.bz2 otp-3ff0914b5625b8ef76e6ff5a2f2db1c563ebed3c.zip |
Expand and squeeze literal integers/utf8 bin segments
This commit adds two operations when handling literal
integers and literal utf8 segments in the v3_kernel pass.
The first operation is to expand all literal integers with
size more than 8 and literal utf8s into integers with size
of 8 (and potentially an integer with size less than 8 at
the end).
This expansion simplifies the code in other operations
inside v3_kernel and ensure they apply more consistently.
For instance, literal binary matching now applies to both
regular and utf8 strings. Furthermore, we can more
efficiently group clauses.
For instance, the following code:
foo(<<$á/utf8, X/binary>>) -> foo(X);
foo(<<$é/utf8, X/binary>>) -> foo(X);
foo(<<>>) -> ok.
Becomes a bs_get_integer_16 comparing 50089 and 50081,
allowing us to skip the utf8 conversion at runtime.
However, since expanding an integer of size 16 into two of
size 8 can be less efficient when matching at runtime,
later we do another pass, where we squeeze all of those
integers together into an integer with maximum size of 24.
This allows prefix matching, such as:
foo(<<"aaaa", X/binary>>) -> foo(X);
foo(<<"bbbb", X/binary>>) -> foo(X);
foo(<<>>) -> ok.
To run more than 2x faster (as long as all clauses match on
a given prefix).
Compilation times and binary size are roughly the same.
Diffstat (limited to 'lib/crypto/c_src/crypto.c')
0 files changed, 0 insertions, 0 deletions