]> granicus.if.org Git - php/commitdiff
Reduce the amount of copying in the mainloop. We copy tag/arg only, if we
authorSascha Schumann <sas@php.net>
Tue, 19 Sep 2000 20:19:03 +0000 (20:19 +0000)
committerSascha Schumann <sas@php.net>
Tue, 19 Sep 2000 20:19:03 +0000 (20:19 +0000)
need to preserve them for a new loop iteration (after we leave mainloop).
Otherwise, we can just let them point to the work area.

ext/standard/url_scanner_ex.c
ext/standard/url_scanner_ex.h
ext/standard/url_scanner_ex.re

index 205edd68721348b02a4c4d7a1f7a1905f832022d..7f3f0fbf7b30c0aecb77eaf0effd5822d938e960 100644 (file)
@@ -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 @@ 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;
+       dest->c = (char *) src;
 }
 
 static inline void smart_str_appends(smart_str *dest, const char *src)
@@ -119,12 +119,21 @@ static inline void attach_url(smart_str *url, smart_str *name, smart_str *val, c
        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)
@@ -132,9 +141,11 @@ 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 @@ static inline void tag_arg(url_adapt_state_t *ctx PLS_DC)
        smart_str_appends(&ctx->result, "\"");
 }
 
-#line 151
+#line 162
 
 
 #define NEXT continue
@@ -160,12 +171,12 @@ static inline void tag_arg(url_adapt_state_t *ctx PLS_DC)
        
 #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 @@ static void mainloop(url_adapt_state_t *ctx, smart_str *newstuff)
 {
        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 @@ yy0:
        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 @@ yy9:        yyaccept = 0;
        if(yych == ' ') goto yy12;
        if(yych == '>') goto yy12;
 yy10:
-#line 225
+#line 242
        { 
                                                YYCURSOR--; 
                                                GO(STATE_PLAIN);
@@ -328,11 +345,11 @@ yy11:     yych = *++YYCURSOR;
        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 @@ yy16:       YYCURSOR = YYMARKER;
        case 0: goto yy10;
        }
 }
-#line 231
+#line 248
 
                        break;
 
@@ -404,14 +421,14 @@ yy19:yy20:        ++YYCURSOR;
        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 @@ yy24:
                                                COPY_ALL;
                                }
 }
-#line 246
+#line 263
 
                        break;
 
@@ -472,7 +489,7 @@ yy25:
        if(yych <= '<') goto yy30;
        if(yych >= '?') goto yy30;
 yy27:
-#line 264
+#line 281
        {
                                                arg_start = YYCURSOR;
                                                ctx->state--;
@@ -511,12 +528,12 @@ yy35:     ++YYCURSOR;
        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 @@ yy37:
                                                COPY_ALL;
                                }
 }
-#line 269
+#line 286
 
                        break;
 
@@ -588,7 +605,7 @@ yy40:       yyaccept = 0;
        yych = *(YYMARKER = ++YYCURSOR);
        if(yych != '^') goto yy51;
 yy41:
-#line 298
+#line 315
        {
                                                YYCURSOR--;
                                                ctx->state = 2;
@@ -602,7 +619,7 @@ yy43:       yych = *++YYCURSOR;
        goto yy41;
 yy44:  yych = *++YYCURSOR;
 yy45:
-#line 286
+#line 303
        {
                                                YYCURSOR--;
                                                para_start = NULL;
@@ -643,7 +660,7 @@ yy52:       yych = *++YYCURSOR;
        if(yych != '>') goto yy47;
 yy53:  yych = *++YYCURSOR;
 yy54:
-#line 274
+#line 291
        {
                                                YYCURSOR--;
                                                para_start = NULL;
@@ -669,7 +686,7 @@ yy57:       if(yybm[0+yych] & 128)  goto yy56;
 yy58:  yych = *++YYCURSOR;
        goto yy54;
 }
-#line 303
+#line 320
 
                        break;
                }
@@ -681,6 +698,15 @@ yy58:      yych = *++YYCURSOR;
        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 @@ PHP_RSHUTDOWN_FUNCTION(url_scanner)
 
        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 e3e6501b824c068439dc37b12140faa1a9bf0219..e207a4b4311c2f2b4cb1ae30d804b3e3b5df2751 100644 (file)
@@ -31,6 +31,8 @@ typedef struct {
 } smart_str;
 
 typedef struct {
+       smart_str c_arg;
+       smart_str c_tag;
        smart_str arg;
        smart_str tag;
        smart_str para;
index 3f8a4e8e4747d5af6cb825f1d46f83d05c676145..ea4f24ad216a5f83d616a739a47841a6fee8fbf5 100644 (file)
@@ -85,7 +85,7 @@ 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;
+       dest->c = (char *) src;
 }
 
 static inline void smart_str_appends(smart_str *dest, const char *src)
@@ -117,12 +117,21 @@ static inline void attach_url(smart_str *url, smart_str *name, smart_str *val, c
        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)
@@ -130,9 +139,11 @@ 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 @@ all = [\000-\377];
        
 #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 @@ static void mainloop(url_adapt_state_t *ctx, smart_str *newstuff)
 {
        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 @@ static void mainloop(url_adapt_state_t *ctx, smart_str *newstuff)
   [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 @@ static void mainloop(url_adapt_state_t *ctx, smart_str *newstuff)
                                                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 @@ static void mainloop(url_adapt_state_t *ctx, smart_str *newstuff)
        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 @@ PHP_RSHUTDOWN_FUNCTION(url_scanner)
 
        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;