aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-01-17 16:01:28 +0100
committerBjörn Gustavsson <[email protected]>2018-01-19 09:52:29 +0100
commitc2a9915a451a3c6ad618f55a2871a43403333b7f (patch)
treee24292cd098b1216497252ae45d192a310bc9bd8 /erts
parentdb58a0c04ca183de5e5436e0ae97e3f109a458fe (diff)
downloadotp-c2a9915a451a3c6ad618f55a2871a43403333b7f.tar.gz
otp-c2a9915a451a3c6ad618f55a2871a43403333b7f.tar.bz2
otp-c2a9915a451a3c6ad618f55a2871a43403333b7f.zip
Optimize matching of an 'utf8' segment in the binary syntax
Matching out an 8-bit integer is faster than matching out an utf8-encoded code point, even if the value of the code point is less than 128. The reason is that matching out an 8-bit integer is specially optimized to avoid a function call. Do a similar optimization for matching out an utf8 segment.
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/beam/bs_instrs.tab16
1 files changed, 15 insertions, 1 deletions
diff --git a/erts/emulator/beam/bs_instrs.tab b/erts/emulator/beam/bs_instrs.tab
index 9f03b19731..b11903a47b 100644
--- a/erts/emulator/beam/bs_instrs.tab
+++ b/erts/emulator/beam/bs_instrs.tab
@@ -919,9 +919,23 @@ i_bs_get_integer(Fail, Live, FlagsAndUnit, Ms, Sz, Dst) {
}
i_bs_get_utf8(Ctx, Fail, Dst) {
+ Eterm result;
ErlBinMatchBuffer* mb = ms_matchbuffer($Ctx);
- Eterm result = erts_bs_get_utf8(mb);
+ if (mb->size - mb->offset < 8) {
+ $FAIL($Fail);
+ }
+ if (BIT_OFFSET(mb->offset) != 0) {
+ result = erts_bs_get_utf8(mb);
+ } else {
+ byte b = mb->base[BYTE_OFFSET(mb->offset)];
+ if (b < 128) {
+ result = make_small(b);
+ mb->offset += 8;
+ } else {
+ result = erts_bs_get_utf8(mb);
+ }
+ }
if (is_non_value(result)) {
$FAIL($Fail);
}