|
21 | 21 | #include "php.h" |
22 | 22 | #include "zend_smart_str.h" /* for smart_str */ |
23 | 23 |
|
| 24 | +#ifdef __SSE2__ |
| 25 | +#include <emmintrin.h> |
| 26 | +#endif |
| 27 | + |
24 | 28 | #include "php_yaf.h" |
25 | 29 | #include "yaf_application.h" |
26 | 30 | #include "yaf_namespace.h" |
@@ -221,7 +225,33 @@ static inline char* yaf_loader_sanitize_name(char *name, size_t len) /* {{{ */ { |
221 | 225 | /* replace all '\' to '_' */ |
222 | 226 | sanitized_name = estrndup(name, len); |
223 | 227 | pos = sanitized_name + (pos - name); |
224 | | - while ((*pos = '_', pos = memchr(pos, '\\', len - (pos - sanitized_name)))); |
| 228 | +#ifdef __SSE2__ |
| 229 | + do { |
| 230 | + const __m128i slash = _mm_set1_epi8('\\'); |
| 231 | + const __m128i delta = _mm_set1_epi8('_' - '\\'); |
| 232 | + len -= (pos - sanitized_name); |
| 233 | + while (len >= 16) { |
| 234 | + __m128i op = _mm_loadu_si128((__m128i *)pos); |
| 235 | + __m128i eq = _mm_cmpeq_epi8(op, slash); |
| 236 | + if (_mm_movemask_epi8(eq)) { |
| 237 | + eq = _mm_and_si128(eq, delta); |
| 238 | + op = _mm_add_epi8(op, eq); |
| 239 | + _mm_storeu_si128((__m128i*)pos, op); |
| 240 | + } |
| 241 | + len -= 16; |
| 242 | + pos += 16; |
| 243 | + } |
| 244 | + } while (0); |
| 245 | + |
| 246 | + if (len) { |
| 247 | + name = pos; |
| 248 | + while ((pos = memchr(pos, '\\', len - (pos - name)))) { |
| 249 | + *pos++ = '_'; |
| 250 | + } |
| 251 | + } |
| 252 | +#else |
| 253 | + while ((*pos++ = '_', pos = memchr(pos, '\\', len - (pos - sanitized_name)))); |
| 254 | +#endif |
225 | 255 | } |
226 | 256 |
|
227 | 257 | return sanitized_name; |
|
0 commit comments