]> granicus.if.org Git - php/commitdiff
Another speedup by avoiding string copies.
authorSascha Schumann <sas@php.net>
Tue, 19 Sep 2000 18:17:28 +0000 (18:17 +0000)
committerSascha Schumann <sas@php.net>
Tue, 19 Sep 2000 18:17:28 +0000 (18:17 +0000)
15% speed gain in test case (rewriting 1M URLs).

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

index 6ddda44758d4fe58704543ec68942f1275251fe2..7fca58e89423f86b40e0e0932ab23bee78cea54a 100644 (file)
@@ -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 @@ static inline void smart_str_appendl(smart_str *dest, const char *src, size_t le
        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 @@ static inline void smart_str_copys(smart_str *dest, const char *src)
        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 @@ static inline void tag_arg(url_adapt_state_t *ctx PLS_DC)
        smart_str_appends(&ctx->result, "\"");
 }
 
-#line 139
+#line 151
 
 
 #define NEXT continue
@@ -238,17 +250,17 @@ yy0:
        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 @@ yy9:        yyaccept = 0;
        if(yych == ' ') goto yy12;
        if(yych == '>') goto yy12;
 yy10:
-#line 213
+#line 225
        { 
                                                YYCURSOR--; 
                                                GO(STATE_PLAIN);
@@ -316,7 +328,7 @@ yy11:       yych = *++YYCURSOR;
        goto yy10;
 yy12:  yych = *++YYCURSOR;
 yy13:
-#line 203
+#line 215
        { 
                                                YYCURSOR--; 
                                                arg_start = YYCURSOR;
@@ -338,7 +350,7 @@ yy16:       YYCURSOR = YYMARKER;
        case 0: goto yy10;
        }
 }
-#line 219
+#line 231
 
                        break;
 
@@ -392,14 +404,14 @@ yy19:yy20:        ++YYCURSOR;
        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 @@ yy24:
                                                COPY_ALL;
                                }
 }
-#line 234
+#line 246
 
                        break;
 
@@ -460,7 +472,7 @@ yy25:
        if(yych <= '<') goto yy30;
        if(yych >= '?') goto yy30;
 yy27:
-#line 252
+#line 264
        {
                                                arg_start = YYCURSOR;
                                                ctx->state--;
@@ -499,12 +511,12 @@ yy35:     ++YYCURSOR;
        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 @@ yy37:
                                                COPY_ALL;
                                }
 }
-#line 257
+#line 269
 
                        break;
 
@@ -576,7 +588,7 @@ yy40:       yyaccept = 0;
        yych = *(YYMARKER = ++YYCURSOR);
        if(yych != '^') goto yy51;
 yy41:
-#line 286
+#line 298
        {
                                                YYCURSOR--;
                                                ctx->state = 2;
@@ -590,11 +602,11 @@ yy43:     yych = *++YYCURSOR;
        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 @@ yy52:     yych = *++YYCURSOR;
        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 @@ yy57:       if(yybm[0+yych] & 128)  goto yy56;
 yy58:  yych = *++YYCURSOR;
        goto yy54;
 }
-#line 291
+#line 303
 
                        break;
                }
@@ -699,19 +711,25 @@ char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char
        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 @@ PHP_RSHUTDOWN_FUNCTION(url_scanner)
 {
        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 d07774be9b79738c5fed3692ee6d261e8ae974a4..15ac674b242d93f8ec8cfe1eaae42bf5fc6549da 100644 (file)
@@ -81,6 +81,13 @@ static inline void smart_str_appendl(smart_str *dest, const char *src, size_t le
        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 @@ static inline void smart_str_copys(smart_str *dest, const char *src)
        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 @@ 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
@@ -262,7 +274,7 @@ static void mainloop(url_adapt_state_t *ctx, smart_str *newstuff)
   ["] (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 @@ static void mainloop(url_adapt_state_t *ctx, smart_str *newstuff)
   (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 *url_adapt_ext(const char *src, size_t srclen, const char *name, const char
        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 @@ PHP_RSHUTDOWN_FUNCTION(url_scanner)
 {
        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