cvs: php4 /ext/standard url_scanner_ex.c url_scanner_ex.h url_scanner_ex.re
| From: | Sascha Schumann | Date: | Tue, 19 Sep 2000 20:19:04 +0000 |
| Subject: | cvs: php4 /ext/standard url_scanner_ex.c url_scanner_ex.h url_scanner_ex.re | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1800@lists.php.net to get a copy of this message | ||
sas Tue Sep 19 13:19:04 2000 EDT
Modified files:
/php4/ext/standard url_scanner_ex.c url_scanner_ex.h
url_scanner_ex.re
Log:
Reduce the amount of copying in the mainloop. We copy tag/arg only, if we
need to preserve them for a new loop iteration (after we leave mainloop).
Otherwise, we can just let them point to the work area.
Index: php4/ext/standard/url_scanner_ex.c
diff -u php4/ext/standard/url_scanner_ex.c:1.6 php4/ext/standard/url_scanner_ex.c:1.7
--- php4/ext/standard/url_scanner_ex.c:1.6 Tue Sep 19 12:18:41 2000
+++ php4/ext/standard/url_scanner_ex.c Tue Sep 19 13:19:03 2000
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.5 on Tue Sep 19 21:17:19 2000 */
+/* Generated by re2c 0.5 on Tue Sep 19 22:11:37 2000 */
#line 1 "/home/sas/src/php4/ext/standard/url_scanner_ex.re"
/*
+----------------------------------------------------------------------+
@@ -87,7 +87,7 @@
{
dest->len = len;
dest->a = len + 1;
- dest->c = src;
+ dest->c = (char *) src;
}
static inline void smart_str_appends(smart_str *dest, const char *src)
@@ -119,22 +119,33 @@
smart_str_append(url, val);
}
-static char *check_tag_arg[] = {
- "a", "href",
- "area", "href",
- "frame", "source",
- "img", "src",
- NULL
+struct php_tag_arg {
+ char *tag;
+ int taglen;
+ char *arg;
+ int arglen;
};
+#define TAG_ARG_ENTRY(a,b) {#a,sizeof(#a)-1,#b,sizeof(#b)-1},
+
+static struct php_tag_arg check_tag_arg[] = {
+ TAG_ARG_ENTRY(a, href)
+ TAG_ARG_ENTRY(area, href)
+ TAG_ARG_ENTRY(frame, source)
+ TAG_ARG_ENTRY(img, src)
+ {0}
+};
+
static inline void tag_arg(url_adapt_state_t *ctx PLS_DC)
{
char f = 0;
int i;
- for (i = 0; check_tag_arg[i]; i += 2) {
- if (strcasecmp(ctx->tag.c, check_tag_arg[i]) == 0
- && strcasecmp(ctx->arg.c, check_tag_arg[i + 1]) == 0) {
+ for (i = 0; check_tag_arg[i].tag; i++) {
+ if (check_tag_arg[i].arglen == ctx->arg.len
+ && check_tag_arg[i].taglen == ctx->tag.len
+ && strncasecmp(ctx->tag.c, check_tag_arg[i].tag, ctx->tag.len) == 0
+ && strncasecmp(ctx->arg.c, check_tag_arg[i].arg, ctx->arg.len) == 0) {
f = 1;
break;
}
@@ -148,7 +159,7 @@
smart_str_appends(&ctx->result, "\"");
}
-#line 151
+#line 162
#define NEXT continue
@@ -160,12 +171,12 @@
#define YYFILL(n) goto finish
#define YYCTYPE unsigned char
-#define YYLIMIT (ctx->work.c+ctx->work.len)
+#define YYLIMIT endptr
#define YYCURSOR cursor
#define YYMARKER marker
#define HANDLE_FORM \
- if (strcasecmp(ctx->tag.c, "form") == 0) { \
+ if (ctx->tag.len == 4 && strncasecmp(ctx->tag.c, "form", ctx->tag.len)
== 0) { \
smart_str_appends(&ctx->result, "><INPUT TYPE=HIDDEN NAME=\""); \
smart_str_append(&ctx->result, &ctx->name); \
smart_str_appends(&ctx->result, "\" VALUE=\""); \
@@ -187,14 +198,20 @@
{
char *para_start, *arg_start, *tag_start;
char *start = NULL;
- char *cursor, *marker;
+ char *cursor;
+ char *marker;
+ char *endptr;
PLS_FETCH();
arg_start = para_start = tag_start = NULL;
smart_str_append(&ctx->work, newstuff);
smart_str_free(&ctx->result);
+ smart_str_setl(&ctx->arg, ctx->c_arg.c, ctx->c_arg.len);
+ smart_str_setl(&ctx->tag, ctx->c_tag.c, ctx->c_tag.len);
+
cursor = ctx->work.c;
+ endptr = ctx->work.c + ctx->work.len;
while (YYCURSOR < YYLIMIT) {
start = YYCURSOR;
@@ -250,17 +267,17 @@
if(yybm[0+yych] & 128) goto yy4;
yy2: yych = *++YYCURSOR;
yy3:
-#line 208
+#line 225
{ 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 209
+#line 226
{ COPY_ALL; }
}
-#line 210
+#line 227
break;
@@ -317,7 +334,7 @@
if(yych == ' ') goto yy12;
if(yych == '>') goto yy12;
yy10:
-#line 225
+#line 242
{
YYCURSOR--;
GO(STATE_PLAIN);
@@ -328,11 +345,11 @@
goto yy10;
yy12: yych = *++YYCURSOR;
yy13:
-#line 215
+#line 232
{
YYCURSOR--;
arg_start = YYCURSOR;
- smart_str_copyl(&ctx->tag, start, YYCURSOR - start);
+ smart_str_setl(&ctx->tag, start, YYCURSOR - start);
#ifdef SCANNER_DEBUG
printf("TAG(%s)\n", ctx->tag.c);
#endif
@@ -350,7 +367,7 @@
case 0: goto yy10;
}
}
-#line 231
+#line 248
break;
@@ -404,14 +421,14 @@
yych = *YYCURSOR;
yy21: if(yybm[0+yych] & 128) goto yy20;
yy22:
-#line 236
+#line 253
{
GO(STATE_ARG);
NEXT;
}
yy23: yych = *++YYCURSOR;
yy24:
-#line 240
+#line 257
{
HANDLE_FORM;
GO(STATE_PLAIN);
@@ -419,7 +436,7 @@
COPY_ALL;
}
}
-#line 246
+#line 263
break;
@@ -472,7 +489,7 @@
if(yych <= '<') goto yy30;
if(yych >= '?') goto yy30;
yy27:
-#line 264
+#line 281
{
arg_start = YYCURSOR;
ctx->state--;
@@ -511,12 +528,12 @@
yych = *YYCURSOR;
yy36: if(yych == ' ') goto yy35;
yy37:
-#line 252
+#line 269
{
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
@@ -525,7 +542,7 @@
COPY_ALL;
}
}
-#line 269
+#line 286
break;
@@ -588,7 +605,7 @@
yych = *(YYMARKER = ++YYCURSOR);
if(yych != '^') goto yy51;
yy41:
-#line 298
+#line 315
{
YYCURSOR--;
ctx->state = 2;
@@ -602,7 +619,7 @@
goto yy41;
yy44: yych = *++YYCURSOR;
yy45:
-#line 286
+#line 303
{
YYCURSOR--;
para_start = NULL;
@@ -643,7 +660,7 @@
if(yych != '>') goto yy47;
yy53: yych = *++YYCURSOR;
yy54:
-#line 274
+#line 291
{
YYCURSOR--;
para_start = NULL;
@@ -669,7 +686,7 @@
yy58: yych = *++YYCURSOR;
goto yy54;
}
-#line 303
+#line 320
break;
}
@@ -681,6 +698,15 @@
ctx->work.len = n
finish:
+ if (ctx->arg.c)
+ smart_str_copyl(&ctx->c_arg, ctx->arg.c, ctx->arg.len);
+ else
+ smart_str_free(&ctx->c_arg);
+ if (ctx->tag.c)
+ smart_str_copyl(&ctx->c_tag, ctx->tag.c, ctx->tag.len);
+ else
+ smart_str_free(&ctx->c_tag);
+
if (ctx->state >= 2) {
if (para_start) {
PRESERVE(para_start);
@@ -747,8 +773,8 @@
smart_str_free(&BG(url_adapt_state).result);
smart_str_free(&BG(url_adapt_state).work);
- smart_str_free(&BG(url_adapt_state).tag);
- smart_str_free(&BG(url_adapt_state).arg);
+ smart_str_free(&BG(url_adapt_state).c_tag);
+ smart_str_free(&BG(url_adapt_state).c_arg);
smart_str_free(&BG(url_adapt_state).para);
return SUCCESS;
Index: php4/ext/standard/url_scanner_ex.h
diff -u php4/ext/standard/url_scanner_ex.h:1.1 php4/ext/standard/url_scanner_ex.h:1.2
--- php4/ext/standard/url_scanner_ex.h:1.1 Tue Sep 19 10:32:27 2000
+++ php4/ext/standard/url_scanner_ex.h Tue Sep 19 13:19:03 2000
@@ -31,6 +31,8 @@
} smart_str;
typedef struct {
+ smart_str c_arg;
+ smart_str c_tag;
smart_str arg;
smart_str tag;
smart_str para;
Index: php4/ext/standard/url_scanner_ex.re
diff -u php4/ext/standard/url_scanner_ex.re:1.6 php4/ext/standard/url_scanner_ex.re:1.7
--- php4/ext/standard/url_scanner_ex.re:1.6 Tue Sep 19 12:18:41 2000
+++ php4/ext/standard/url_scanner_ex.re Tue Sep 19 13:19:03 2000
@@ -85,7 +85,7 @@
{
dest->len = len;
dest->a = len + 1;
- dest->c = src;
+ dest->c = (char *) src;
}
static inline void smart_str_appends(smart_str *dest, const char *src)
@@ -117,22 +117,33 @@
smart_str_append(url, val);
}
-static char *check_tag_arg[] = {
- "a", "href",
- "area", "href",
- "frame", "source",
- "img", "src",
- NULL
+struct php_tag_arg {
+ char *tag;
+ int taglen;
+ char *arg;
+ int arglen;
};
+#define TAG_ARG_ENTRY(a,b) {#a,sizeof(#a)-1,#b,sizeof(#b)-1},
+
+static struct php_tag_arg check_tag_arg[] = {
+ TAG_ARG_ENTRY(a, href)
+ TAG_ARG_ENTRY(area, href)
+ TAG_ARG_ENTRY(frame, source)
+ TAG_ARG_ENTRY(img, src)
+ {0}
+};
+
static inline void tag_arg(url_adapt_state_t *ctx PLS_DC)
{
char f = 0;
int i;
- for (i = 0; check_tag_arg[i]; i += 2) {
- if (strcasecmp(ctx->tag.c, check_tag_arg[i]) == 0
- && strcasecmp(ctx->arg.c, check_tag_arg[i + 1]) == 0) {
+ for (i = 0; check_tag_arg[i].tag; i++) {
+ if (check_tag_arg[i].arglen == ctx->arg.len
+ && check_tag_arg[i].taglen == ctx->tag.len
+ && strncasecmp(ctx->tag.c, check_tag_arg[i].tag, ctx->tag.len) == 0
+ && strncasecmp(ctx->arg.c, check_tag_arg[i].arg, ctx->arg.len) == 0) {
f = 1;
break;
}
@@ -159,12 +170,12 @@
#define YYFILL(n) goto finish
#define YYCTYPE unsigned char
-#define YYLIMIT (ctx->work.c+ctx->work.len)
+#define YYLIMIT endptr
#define YYCURSOR cursor
#define YYMARKER marker
#define HANDLE_FORM \
- if (strcasecmp(ctx->tag.c, "form") == 0) { \
+ if (ctx->tag.len == 4 && strncasecmp(ctx->tag.c, "form", ctx->tag.len)
== 0) { \
smart_str_appends(&ctx->result, "><INPUT TYPE=HIDDEN NAME=\""); \
smart_str_append(&ctx->result, &ctx->name); \
smart_str_appends(&ctx->result, "\" VALUE=\""); \
@@ -186,14 +197,20 @@
{
char *para_start, *arg_start, *tag_start;
char *start = NULL;
- char *cursor, *marker;
+ char *cursor;
+ char *marker;
+ char *endptr;
PLS_FETCH();
arg_start = para_start = tag_start = NULL;
smart_str_append(&ctx->work, newstuff);
smart_str_free(&ctx->result);
+ smart_str_setl(&ctx->arg, ctx->c_arg.c, ctx->c_arg.len);
+ smart_str_setl(&ctx->tag, ctx->c_tag.c, ctx->c_tag.len);
+
cursor = ctx->work.c;
+ endptr = ctx->work.c + ctx->work.len;
while (YYCURSOR < YYLIMIT) {
start = YYCURSOR;
@@ -215,7 +232,7 @@
[a-zA-Z]+ [ >] {
YYCURSOR--;
arg_start = YYCURSOR;
- smart_str_copyl(&ctx->tag, start, YYCURSOR - start);
+ smart_str_setl(&ctx->tag, start, YYCURSOR - start);
#ifdef SCANNER_DEBUG
printf("TAG(%s)\n", ctx->tag.c);
#endif
@@ -253,7 +270,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
@@ -311,6 +328,15 @@
ctx->work.len = n
finish:
+ if (ctx->arg.c)
+ smart_str_copyl(&ctx->c_arg, ctx->arg.c, ctx->arg.len);
+ else
+ smart_str_free(&ctx->c_arg);
+ if (ctx->tag.c)
+ smart_str_copyl(&ctx->c_tag, ctx->tag.c, ctx->tag.len);
+ else
+ smart_str_free(&ctx->c_tag);
+
if (ctx->state >= 2) {
if (para_start) {
PRESERVE(para_start);
@@ -377,8 +403,8 @@
smart_str_free(&BG(url_adapt_state).result);
smart_str_free(&BG(url_adapt_state).work);
- smart_str_free(&BG(url_adapt_state).tag);
- smart_str_free(&BG(url_adapt_state).arg);
+ smart_str_free(&BG(url_adapt_state).c_tag);
+ smart_str_free(&BG(url_adapt_state).c_arg);
smart_str_free(&BG(url_adapt_state).para);
return SUCCESS;