diff options
author | Sverker Eriksson <[email protected]> | 2018-04-19 17:41:07 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2018-04-19 17:41:07 +0200 |
commit | 50a2cb7a044076347da0a1ee98a71b1c27a553b7 (patch) | |
tree | 6469d0020b52ad4a125a2a9081cb9fffe6d73482 /lib/erl_interface/src/decode/decode_atom.c | |
parent | 40dc6b9fed7d51a204e0d69b7bba7e8cb6496ae5 (diff) | |
parent | 1ab478a7ce281f7cdce01df2fe04953c0770fdbc (diff) | |
download | otp-50a2cb7a044076347da0a1ee98a71b1c27a553b7.tar.gz otp-50a2cb7a044076347da0a1ee98a71b1c27a553b7.tar.bz2 otp-50a2cb7a044076347da0a1ee98a71b1c27a553b7.zip |
Merge 'sverker/optimize-atom-enc-dec/ERIERL-150/OTP-15023'
into master
as'sverker/master/optimize-atom-enc-dec/ERIERL-150'
Diffstat (limited to 'lib/erl_interface/src/decode/decode_atom.c')
-rw-r--r-- | lib/erl_interface/src/decode/decode_atom.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/erl_interface/src/decode/decode_atom.c b/lib/erl_interface/src/decode/decode_atom.c index b3bba82434..87cd75b1be 100644 --- a/lib/erl_interface/src/decode/decode_atom.c +++ b/lib/erl_interface/src/decode/decode_atom.c @@ -92,6 +92,51 @@ int ei_decode_atom_as(const char *buf, int *index, char* p, int destlen, } + +#ifdef HAVE_UNALIGNED_WORD_ACCESS + +#if SIZEOF_VOID_P == SIZEOF_LONG +typedef unsigned long AsciiWord; +#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG +typedef unsigned long long AsciiWord; +#else +# error "Uknown word type" +#endif + +#if SIZEOF_VOID_P == 4 +# define ASCII_CHECK_MASK ((AsciiWord)0x80808080U) +#elif SIZEOF_VOID_P == 8 +# define ASCII_CHECK_MASK ((AsciiWord)0x8080808080808080U) +#endif + +static int ascii_fast_track(char* dst, const char* src, int slen, int destlen) +{ + const AsciiWord* src_word = (AsciiWord*) src; + const AsciiWord* const src_word_end = src_word + (slen / sizeof(AsciiWord)); + + if (destlen < slen) + return 0; + + if (dst) { + AsciiWord* dst_word = (AsciiWord*)dst; + + while (src_word < src_word_end) { + if ((*src_word & ASCII_CHECK_MASK) != 0) + break; + *dst_word++ = *src_word++; + } + } + else { + while (src_word < src_word_end) { + if ((*src_word & ASCII_CHECK_MASK) != 0) + break; + src_word++; + } + } + return (char*)src_word - src; +} +#endif /* HAVE_UNALIGNED_WORD_ACCESS */ + int utf8_to_latin1(char* dst, const char* src, int slen, int destlen, erlang_char_encoding* res_encp) { @@ -99,6 +144,15 @@ int utf8_to_latin1(char* dst, const char* src, int slen, int destlen, const char* const dst_end = dst + destlen; int found_non_ascii = 0; +#ifdef HAVE_UNALIGNED_WORD_ACCESS + { + int aft = ascii_fast_track(dst, src, slen, destlen); + src += aft; + slen -= aft; + dst += aft; + } +#endif + while (slen > 0) { if (dst >= dst_end) return -1; if ((src[0] & 0x80) == 0) { @@ -136,6 +190,14 @@ int latin1_to_utf8(char* dst, const char* src, int slen, int destlen, const char* const dst_end = dst + destlen; int found_non_ascii = 0; +#ifdef HAVE_UNALIGNED_WORD_ACCESS + { + int aft = ascii_fast_track(dst, src, slen, destlen); + dst += aft; + src += aft; + } +#endif + while (src < src_end) { if (dst >= dst_end) return -1; if ((src[0] & 0x80) == 0) { |