iliaa Tue Jun 15 21:54:00 2004 EDT
Modified files: (Branch: PHP_4_3)
/php-src/ext/standard string.c
Log:
New & improved strspn() & strcspn(), ~30% in most cases.
# In part based on patch by Alexander Valyalkin
http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.333.2.40&r2=1.333.2.41&ty=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.333.2.40
php-src/ext/standard/string.c:1.333.2.41
--- php-src/ext/standard/string.c:1.333.2.40 Mon Jun 14 22:02:45 2004
+++ php-src/ext/standard/string.c Tue Jun 15 21:53:59 2004
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.333.2.40 2004/06/15 02:02:45 iliaa Exp $ */
+/* $Id: string.c,v 1.333.2.41 2004/06/16 01:53:59 iliaa Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -203,10 +203,10 @@
{
char *s11, *s22;
int len1, len2;
- long start, len;
-
- start = 0;
- len = 0;
+ long start = 0, len = 0;
+ unsigned char match[256] = {0};
+ char *rs, *s, *e;
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", &s11, &len1,
&s22, &len2, &start, &len) == FAILURE) {
return;
@@ -238,18 +238,17 @@
len = len1 - start;
}
- if (behavior == STR_STRSPN) {
- RETURN_LONG(php_strspn(s11 + start /*str1_start*/,
- s22 /*str2_start*/,
- s11 + start + len /*str1_end*/,
- s22 + len2 /*str2_end*/));
- } else if (behavior == STR_STRCSPN) {
- RETURN_LONG(php_strcspn(s11 + start /*str1_start*/,
- s22 /*str2_start*/,
- s11 + start + len /*str1_end*/,
- s22 + len2 /*str2_end*/));
+ s = s22;
+ e = s22 + len2;
+ while (s < e) {
+ match[(int)(unsigned char)*s++] = 1;
}
-
+
+ rs = s = s11 + start;
+ e = s11 + start + len;
+ while (s <= e && match[(int)(unsigned char)*s++] != behavior);
+
+ RETURN_LONG((s - rs) < 1 ? 0 : s - rs - 1);
}
/* {{{ proto int strspn(string str, string mask [, start [, len]])
@@ -1289,42 +1288,6 @@
php_strtolower(s, s_len);
php_strtolower(t, t_len);
return php_memnstr(s, t, t_len, s + s_len);
-}
-/* }}} */
-
-/* {{{ php_strspn
- */
-PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end)
-{
- register const char *p = s1, *spanp;
- register char c = *p;
-
-cont:
- for (spanp = s2; p != s1_end && spanp != s2_end;)
- if (*spanp++ == c) {
- c = *(++p);
- goto cont;
- }
- return (p - s1);
-}
-/* }}} */
-
-/* {{{ php_strcspn
- */
-PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end)
-{
- register const char *p, *spanp;
- register char c = *s1;
-
- for (p = s1;;) {
- spanp = s2;
- do {
- if (*spanp == c || p == s1_end)
- return p - s1;
- } while (spanp++ < s2_end);
- c = *++p;
- }
- /* NOTREACHED */
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php