cvs: php4 /ext/standard url_scanner_ex.c url_scanner_ex.re
| From: | Sascha Schumann | Date: | Tue, 19 Sep 2000 18:17:28 +0000 |
| Subject: | cvs: php4 /ext/standard url_scanner_ex.c url_scanner_ex.re | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1796@lists.php.net to get a copy of this message | ||
sas Tue Sep 19 11:17:28 2000 EDT
Modified files:
/php4/ext/standard url_scanner_ex.re url_scanner_ex.c
Log:
Another speedup by avoiding string copies.
15% speed gain in test case (rewriting 1M URLs).
Index: php4/ext/standard/url_scanner_ex.re
diff -u php4/ext/standard/url_scanner_ex.re:1.4 php4/ext/standard/url_scanner_ex.re:1.5
--- php4/ext/standard/url_scanner_ex.re:1.4 Tue Sep 19 11:01:29 2000
+++ php4/ext/standard/url_scanner_ex.re Tue Sep 19 11:17:28 2000
@@ -81,6 +81,13 @@
smart_str_append(dest, &s);
}
+static inline void smart_str_setl(smart_str *dest, const char *src, size_t len)
+{
+ dest->len = len;
+ dest->a = len + 1;
+ dest->c = src;
+}
+
static inline void smart_str_appends(smart_str *dest, const char *src)
{
smart_str_appendl(dest, src, strlen(src));
@@ -91,6 +98,11 @@
smart_str_copyl(dest, src, strlen(src));
}
+static inline void smart_str_sets(smart_str *dest, const char *src)
+{
+ smart_str_setl(dest, src, strlen(src));
+}
+
static inline void attach_url(smart_str *url, smart_str *name, smart_str *val, const char
*separator)
{
if (strchr(url->c, ':')) return;
@@ -241,7 +253,7 @@
char *p;
for (p = start; isalpha(*p); p++);
- smart_str_copyl(&ctx->arg, start, p - start);
+ smart_str_setl(&ctx->arg, start, p - start);
#ifdef SCANNER_DEBUG
printf("ARG(%s)\n", ctx->arg.c);
#endif
@@ -262,7 +274,7 @@
["] (all\[^>"])* ["] [ >] {
YYCURSOR--;
para_start = NULL;
- smart_str_copyl(&ctx->para, start + 1, YYCURSOR - start - 2);
+ smart_str_setl(&ctx->para, start + 1, YYCURSOR - start - 2);
#ifdef SCANNER_DEBUG
printf("PARA(%s)\n", ctx->para.c);
#endif
@@ -274,7 +286,7 @@
(all\[^> ])+ [ >] {
YYCURSOR--;
para_start = NULL;
- smart_str_copyl(&ctx->para, start, YYCURSOR - start);
+ smart_str_setl(&ctx->para, start, YYCURSOR - start);
#ifdef SCANNER_DEBUG
printf("PARA(%s)\n", ctx->para.c);
#endif
@@ -329,19 +341,25 @@
char *ret;
BLS_FETCH();
- smart_str_copys(&BG(url_adapt_state).name, name);
- smart_str_copys(&BG(url_adapt_state).value, value);
+ smart_str_sets(&BG(url_adapt_state).name, name);
+ smart_str_sets(&BG(url_adapt_state).value, value);
str.c = (char *) src;
str.len = srclen;
mainloop(&BG(url_adapt_state), &str);
*newlen = BG(url_adapt_state).result.len;
- //printf("(%d)NEW(%d): %s'\n", srclen, BG(url_adapt_state).result.len,
BG(url_adapt_state).result.c);
+#ifdef SCANNER_DEBUG
+ printf("(%d)NEW(%d): %s'\n", srclen, BG(url_adapt_state).result.len,
BG(url_adapt_state).result.c);
+#endif
+#if 1
ret = BG(url_adapt_state).result.c;
BG(url_adapt_state).result.c = NULL;
return ret;
+#else
+ return strdup(BG(url_adapt_state).result.c);
+#endif
}
PHP_RINIT_FUNCTION(url_scanner)
@@ -357,40 +375,10 @@
{
BLS_FETCH();
- smart_str_free(&BG(url_adapt_state).name);
- smart_str_free(&BG(url_adapt_state).value);
smart_str_free(&BG(url_adapt_state).result);
smart_str_free(&BG(url_adapt_state).work);
- smart_str_free(&BG(url_adapt_state).arg);
- smart_str_free(&BG(url_adapt_state).tag);
- smart_str_free(&BG(url_adapt_state).para);
return SUCCESS;
}
-
-#if 0
-void main()
-{
- url_adapt_state_t ctx;
- smart_str str = {0};
-
- memset(&ctx, 0, sizeof(ctx));
-
- smart_str_copys(&ctx.name, "PHPSESSID");
- smart_str_copys(&ctx.value, "FOOBAR");
- smart_str_copys(&str, "blabla<HTML>asdasd<a c=d target=_b foobar=x");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "lank dontblink href=someurl
onclick=\"xxx\">bla</a>\n<");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "area href=foobar>");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "<form action=blabla ");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "method=post>");
- mainloop(&ctx, &str);
-
- printf("\n%s\n", ctx.result.c);
-}
-#endif
#endif
Index: php4/ext/standard/url_scanner_ex.c
diff -u php4/ext/standard/url_scanner_ex.c:1.4 php4/ext/standard/url_scanner_ex.c:1.5
--- php4/ext/standard/url_scanner_ex.c:1.4 Tue Sep 19 11:01:29 2000
+++ php4/ext/standard/url_scanner_ex.c Tue Sep 19 11:17:28 2000
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.5 on Tue Sep 19 20:01:37 2000 */
+/* Generated by re2c 0.5 on Tue Sep 19 20:15:55 2000 */
#line 1 "/home/sas/src/php4/ext/standard/url_scanner_ex.re"
/*
+----------------------------------------------------------------------+
@@ -83,6 +83,13 @@
smart_str_append(dest, &s);
}
+static inline void smart_str_setl(smart_str *dest, const char *src, size_t len)
+{
+ dest->len = len;
+ dest->a = len + 1;
+ dest->c = src;
+}
+
static inline void smart_str_appends(smart_str *dest, const char *src)
{
smart_str_appendl(dest, src, strlen(src));
@@ -93,6 +100,11 @@
smart_str_copyl(dest, src, strlen(src));
}
+static inline void smart_str_sets(smart_str *dest, const char *src)
+{
+ smart_str_setl(dest, src, strlen(src));
+}
+
static inline void attach_url(smart_str *url, smart_str *name, smart_str *val, const char
*separator)
{
if (strchr(url->c, ':')) return;
@@ -136,7 +148,7 @@
smart_str_appends(&ctx->result, "\"");
}
-#line 139
+#line 151
#define NEXT continue
@@ -238,17 +250,17 @@
if(yybm[0+yych] & 128) goto yy4;
yy2: yych = *++YYCURSOR;
yy3:
-#line 196
+#line 208
{ tag_start = YYCURSOR; GO(STATE_TAG); COPY_ALL;}
yy4: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
yych = *YYCURSOR;
yy5: if(yybm[0+yych] & 128) goto yy4;
yy6:
-#line 197
+#line 209
{ COPY_ALL; }
}
-#line 198
+#line 210
break;
@@ -305,7 +317,7 @@
if(yych == ' ') goto yy12;
if(yych == '>') goto yy12;
yy10:
-#line 213
+#line 225
{
YYCURSOR--;
GO(STATE_PLAIN);
@@ -316,7 +328,7 @@
goto yy10;
yy12: yych = *++YYCURSOR;
yy13:
-#line 203
+#line 215
{
YYCURSOR--;
arg_start = YYCURSOR;
@@ -338,7 +350,7 @@
case 0: goto yy10;
}
}
-#line 219
+#line 231
break;
@@ -392,14 +404,14 @@
yych = *YYCURSOR;
yy21: if(yybm[0+yych] & 128) goto yy20;
yy22:
-#line 224
+#line 236
{
GO(STATE_ARG);
NEXT;
}
yy23: yych = *++YYCURSOR;
yy24:
-#line 228
+#line 240
{
HANDLE_FORM;
GO(STATE_PLAIN);
@@ -407,7 +419,7 @@
COPY_ALL;
}
}
-#line 234
+#line 246
break;
@@ -460,7 +472,7 @@
if(yych <= '<') goto yy30;
if(yych >= '?') goto yy30;
yy27:
-#line 252
+#line 264
{
arg_start = YYCURSOR;
ctx->state--;
@@ -499,12 +511,12 @@
yych = *YYCURSOR;
yy36: if(yych == ' ') goto yy35;
yy37:
-#line 240
+#line 252
{
char *p;
for (p = start; isalpha(*p); p++);
- smart_str_copyl(&ctx->arg, start, p - start);
+ smart_str_setl(&ctx->arg, start, p - start);
#ifdef SCANNER_DEBUG
printf("ARG(%s)\n", ctx->arg.c);
#endif
@@ -513,7 +525,7 @@
COPY_ALL;
}
}
-#line 257
+#line 269
break;
@@ -576,7 +588,7 @@
yych = *(YYMARKER = ++YYCURSOR);
if(yych != '^') goto yy51;
yy41:
-#line 286
+#line 298
{
YYCURSOR--;
ctx->state = 2;
@@ -590,11 +602,11 @@
goto yy41;
yy44: yych = *++YYCURSOR;
yy45:
-#line 274
+#line 286
{
YYCURSOR--;
para_start = NULL;
- smart_str_copyl(&ctx->para, start, YYCURSOR - start);
+ smart_str_setl(&ctx->para, start, YYCURSOR - start);
#ifdef SCANNER_DEBUG
printf("PARA(%s)\n", ctx->para.c);
#endif
@@ -631,11 +643,11 @@
if(yych != '>') goto yy47;
yy53: yych = *++YYCURSOR;
yy54:
-#line 262
+#line 274
{
YYCURSOR--;
para_start = NULL;
- smart_str_copyl(&ctx->para, start + 1, YYCURSOR - start - 2);
+ smart_str_setl(&ctx->para, start + 1, YYCURSOR - start - 2);
#ifdef SCANNER_DEBUG
printf("PARA(%s)\n", ctx->para.c);
#endif
@@ -657,7 +669,7 @@
yy58: yych = *++YYCURSOR;
goto yy54;
}
-#line 291
+#line 303
break;
}
@@ -699,19 +711,25 @@
char *ret;
BLS_FETCH();
- smart_str_copys(&BG(url_adapt_state).name, name);
- smart_str_copys(&BG(url_adapt_state).value, value);
+ smart_str_sets(&BG(url_adapt_state).name, name);
+ smart_str_sets(&BG(url_adapt_state).value, value);
str.c = (char *) src;
str.len = srclen;
mainloop(&BG(url_adapt_state), &str);
*newlen = BG(url_adapt_state).result.len;
- //printf("(%d)NEW(%d): %s'\n", srclen, BG(url_adapt_state).result.len,
BG(url_adapt_state).result.c);
+#ifdef SCANNER_DEBUG
+ printf("(%d)NEW(%d): %s'\n", srclen, BG(url_adapt_state).result.len,
BG(url_adapt_state).result.c);
+#endif
+#if 1
ret = BG(url_adapt_state).result.c;
BG(url_adapt_state).result.c = NULL;
return ret;
+#else
+ return strdup(BG(url_adapt_state).result.c);
+#endif
}
PHP_RINIT_FUNCTION(url_scanner)
@@ -727,40 +745,10 @@
{
BLS_FETCH();
- smart_str_free(&BG(url_adapt_state).name);
- smart_str_free(&BG(url_adapt_state).value);
smart_str_free(&BG(url_adapt_state).result);
smart_str_free(&BG(url_adapt_state).work);
- smart_str_free(&BG(url_adapt_state).arg);
- smart_str_free(&BG(url_adapt_state).tag);
- smart_str_free(&BG(url_adapt_state).para);
return SUCCESS;
}
-
-#if 0
-void main()
-{
- url_adapt_state_t ctx;
- smart_str str = {0};
-
- memset(&ctx, 0, sizeof(ctx));
-
- smart_str_copys(&ctx.name, "PHPSESSID");
- smart_str_copys(&ctx.value, "FOOBAR");
- smart_str_copys(&str, "blabla<HTML>asdasd<a c=d target=_b foobar=x");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "lank dontblink href=someurl
onclick=\"xxx\">bla</a>\n<");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "area href=foobar>");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "<form action=blabla ");
- mainloop(&ctx, &str);
- smart_str_copys(&str, "method=post>");
- mainloop(&ctx, &str);
-
- printf("\n%s\n", ctx.result.c);
-}
-#endif
#endif