diff options
author | Anatol Belski <ab@php.net> | 2017-11-15 16:00:15 +0100 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2017-11-15 16:02:46 +0100 |
commit | 178add7a583c84de1e2c7b5ef1d6c103755ab555 (patch) | |
tree | 11aa70633d4607ff11f93b36589f07679c11079f | |
parent | c6d0c8aa3bac0a4e66b94960863b1f6d49420d7d (diff) | |
download | php-git-178add7a583c84de1e2c7b5ef1d6c103755ab555.tar.gz |
Unroll loop for ASCII check
-rw-r--r-- | win32/codepage.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/win32/codepage.c b/win32/codepage.c index aa57892bf9..ab6d0a1e5f 100644 --- a/win32/codepage.c +++ b/win32/codepage.c @@ -97,6 +97,7 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size {/*{{{*/ wchar_t *ret = NULL; const char *idx = in, *end; + BOOL failed = FALSE; assert(in && in_len ? in[in_len] == '\0' : 1); @@ -114,14 +115,37 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size end = in + in_len; - while (idx != end) { - if (!__isascii(*idx) && '\0' != *idx) { + while (end - idx > 8) { + char ch0 = *idx; + char ch1 = *(idx + 1); + char ch2 = *(idx + 2); + char ch3 = *(idx + 3); + char ch4 = *(idx + 4); + char ch5 = *(idx + 5); + char ch6 = *(idx + 6); + char ch7 = *(idx + 7); + + if (!__isascii(ch0) || !__isascii(ch1) || !__isascii(ch2) || !__isascii(ch3) || + !__isascii(ch4) || !__isascii(ch5) || !__isascii(ch6) || !__isascii(ch7)) { + failed = TRUE; break; } - idx++; + + idx += 8; + } + + /* Finish the job on remaining chars. */ + if (!failed) { + while (idx != end) { + if (!__isascii(*idx) && '\0' != *idx) { + failed = TRUE; + break; + } + idx++; + } } - if (idx == end) { + if (!failed) { size_t i = 0; int k = 0; wchar_t *ret_idx; |