@@ -105,6 +105,7 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size
105
105
{/*{{{*/
106
106
wchar_t * ret , * ret_idx ;
107
107
const char * idx = in , * end ;
108
+ char ch_err = 0 ;
108
109
109
110
assert (in && in_len ? in [in_len ] == '\0' : 1 );
110
111
@@ -123,29 +124,33 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size
123
124
124
125
/* Process unaligned chunk. */
125
126
while (idx < aidx ) {
126
- if (!__isascii (* idx ) && '\0' != * idx ) {
127
- ASCII_FAIL_RETURN ()
128
- }
127
+ ch_err |= * idx ;
129
128
idx ++ ;
130
129
}
130
+ if (ch_err & 0x80 ) {
131
+ ASCII_FAIL_RETURN ()
132
+ }
131
133
132
134
/* Process aligned chunk. */
135
+ __m128i vec_err = _mm_setzero_si128 ();
133
136
while (end - idx > 15 ) {
134
137
const __m128i block = _mm_load_si128 ((__m128i * )idx );
135
- if (_mm_movemask_epi8 (block )) {
136
- ASCII_FAIL_RETURN ()
137
- }
138
+ vec_err = _mm_or_si128 (vec_err , block );
138
139
idx += 16 ;
139
140
}
141
+ if (_mm_movemask_epi8 (vec_err )) {
142
+ ASCII_FAIL_RETURN ()
143
+ }
140
144
}
141
145
142
146
/* Process the trailing part, or otherwise process string < 16 bytes. */
143
147
while (idx < end ) {
144
- if (!__isascii (* idx ) && '\0' != * idx ) {
145
- ASCII_FAIL_RETURN ()
146
- }
148
+ ch_err |= * idx ;
147
149
idx ++ ;
148
150
}
151
+ if (ch_err & 0x80 ) {
152
+ ASCII_FAIL_RETURN ()
153
+ }
149
154
150
155
ret = malloc ((in_len + 1 )* sizeof (wchar_t ));
151
156
if (!ret ) {
@@ -156,9 +161,6 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size
156
161
ret_idx = ret ;
157
162
idx = in ;
158
163
159
- /* Check and conversion could be merged. This however would
160
- be more expencive, if a non ASCII string was passed.
161
- TODO check whether the impact is acceptable. */
162
164
if (in_len > 15 ) {
163
165
const char * aidx = (const char * )ZEND_SLIDE_TO_ALIGNED16 (in );
164
166
0 commit comments