|
83 | 83 | #ifdef HAVE_CONFIG_H |
84 | 84 | #include "config.h" |
85 | 85 | #endif |
| 86 | +#include "zend_operators.h" |
86 | 87 |
|
87 | 88 | #include <stddef.h> |
88 | 89 | #include <string.h> |
@@ -898,54 +899,26 @@ mbfl_strpos( |
898 | 899 | goto out; |
899 | 900 | } |
900 | 901 |
|
901 | | - if (needle_u8->len == 0) { |
902 | | - size_t haystack_length = mbfl_strlen(haystack_u8); |
903 | | - if (offset < 0) { |
904 | | - result = haystack_length + offset; |
905 | | - } else if (reverse) { |
906 | | - result = haystack_length; |
907 | | - } else { |
908 | | - result = (size_t) offset; |
909 | | - } |
910 | | - goto out; |
911 | | - } |
912 | | - |
913 | 902 | if (!reverse) { |
914 | | - size_t jtbl[1 << (sizeof(unsigned char) * 8)]; |
915 | | - size_t needle_u8_len = needle_u8->len; |
916 | | - size_t i; |
917 | | - const unsigned char *p, *q, *e; |
918 | | - const unsigned char *haystack_u8_val = haystack_u8->val, |
919 | | - *needle_u8_val = needle_u8->val; |
920 | | - for (i = 0; i < sizeof(jtbl) / sizeof(*jtbl); ++i) { |
921 | | - jtbl[i] = needle_u8_len + 1; |
922 | | - } |
923 | | - for (i = 0; i < needle_u8_len - 1; ++i) { |
924 | | - jtbl[needle_u8_val[i]] = needle_u8_len - i; |
925 | | - } |
926 | | - e = haystack_u8_val + haystack_u8->len; |
927 | | - p = offset_pointer + needle_u8_len; |
928 | | - if (p > e) { |
929 | | - goto out; |
| 903 | + const char *found_pos = zend_memnstr( |
| 904 | + (const char *) offset_pointer, |
| 905 | + (const char *) needle_u8->val, needle_u8->len, |
| 906 | + (const char *) haystack_u8->val + haystack_u8->len); |
| 907 | + if (found_pos) { |
| 908 | + result = mbfl_pointer_to_offset_utf8( |
| 909 | + haystack_u8->val, (const unsigned char *) found_pos); |
930 | 910 | } |
931 | | - while (p <= e) { |
932 | | - const unsigned char *pv = p; |
933 | | - q = needle_u8_val + needle_u8_len; |
934 | | - for (;;) { |
935 | | - if (q == needle_u8_val) { |
936 | | - result = mbfl_pointer_to_offset_utf8(haystack_u8_val, p); |
937 | | - goto out; |
938 | | - } |
939 | | - if (*--q != *--p) { |
940 | | - break; |
941 | | - } |
942 | | - } |
943 | | - p += jtbl[*p]; |
944 | | - if (p <= pv) { |
945 | | - p = pv + 1; |
| 911 | + } else { |
| 912 | + if (needle_u8->len == 0) { |
| 913 | + size_t haystack_length = mbfl_strlen(haystack_u8); |
| 914 | + if (offset < 0) { |
| 915 | + result = haystack_length + offset; |
| 916 | + } else { |
| 917 | + result = haystack_length; |
946 | 918 | } |
| 919 | + goto out; |
947 | 920 | } |
948 | | - } else { |
| 921 | + |
949 | 922 | size_t jtbl[1 << (sizeof(unsigned char) * 8)]; |
950 | 923 | size_t needle_u8_len = needle_u8->len, needle_len = 0; |
951 | 924 | size_t i; |
|
0 commit comments