]> granicus.if.org Git - php/commitdiff
Use emalloc and friends. Since we reuse all buffers, this does not affect
authorSascha Schumann <sas@php.net>
Wed, 20 Sep 2000 08:40:33 +0000 (08:40 +0000)
committerSascha Schumann <sas@php.net>
Wed, 20 Sep 2000 08:40:33 +0000 (08:40 +0000)
the speed.

The smart_str_* functions don't NUL terminate strings anymore. We can
rely on the length of the strings completely.

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

index 02a0cc473f75bf2e466e7cedce77248421917140..91f25239a8d838ec539cfd81a27e4c55d3068003 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.5 on Wed Sep 20 10:08:57 2000 */
+/* Generated by re2c 0.5 on Wed Sep 20 10:36:10 2000 */
 #line 1 "/home/sas/src/php4/ext/standard/url_scanner_ex.re"
 /*
   +----------------------------------------------------------------------+
@@ -38,6 +38,8 @@
 #define url_adapt_ext url_adapt_ext_ex
 #define url_scanner url_scanner_ex
 
+#define smart_str_0(x) ((x)->c[(x)->len] = '\0')
+
 static inline void smart_str_append(smart_str *dest, smart_str *src)
 {
        size_t newlen;
@@ -47,11 +49,11 @@ static inline void smart_str_append(smart_str *dest, smart_str *src)
        
        newlen = dest->len + src->len;
        if (newlen >= dest->a) {
-               dest->c = realloc(dest->c, newlen + 129);
+               dest->c = erealloc(dest->c, newlen + 129);
                dest->a = newlen + 128;
        }
        memcpy(dest->c + dest->len, src->c, src->len);
-       dest->c[dest->len = newlen] = '\0';
+       dest->len = newlen;
 }
 
 static inline void smart_str_appendc(smart_str *dest, char c)
@@ -60,17 +62,16 @@ static inline void smart_str_appendc(smart_str *dest, char c)
 
        newlen = dest->len + 1;
        if (newlen >= dest->a) {
-               dest->c = realloc(dest->c, newlen + 129);
+               dest->c = erealloc(dest->c, newlen + 129);
                dest->a = newlen + 128;
        }
        dest->c[dest->len++] = c;
-       dest->c[dest->len] = '\0';
 }
 
 static inline void smart_str_free(smart_str *s)
 {
        if (s->c) {
-               free(s->c);
+               efree(s->c);
                s->c = NULL;
        }
        s->a = s->len = 0;
@@ -78,9 +79,8 @@ static inline void smart_str_free(smart_str *s)
 
 static inline void smart_str_copyl(smart_str *dest, const char *src, size_t len)
 {
-       dest->c = realloc(dest->c, len + 1);
+       dest->c = erealloc(dest->c, len + 1);
        memcpy(dest->c, src, len);
-       dest->c[len] = '\0';
        dest->a = dest->len = len;
 }
 
@@ -112,7 +112,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
 {
        register const char *p, *q;
        const char *bash = NULL;
-       char sep = "?";
+       char sep = '?';
        
        q = url->c + url->len;
        
@@ -656,7 +656,6 @@ stop:
        ctx->buf.len = rest;
 }
 
-
 char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen)
 {
        char *ret;
@@ -674,9 +673,11 @@ char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char
        if (ctx->result.len == 0) {
                return strdup("");
        }
-       ret = ctx->result.c;
-       ctx->result.c = NULL;
-       ctx->result.len = ctx->result.a = 0;
+       smart_str_0(&ctx->result);
+       ret = malloc(ctx->result.len + 1);
+       memcpy(ret, ctx->result.c, ctx->result.len + 1);
+       
+       ctx->result.len = 0;
        return ret;
 }
 
index 6e22dd476225d408a61a0637ed2691fbc842ce7c..faac19c49f2000446816367bd168421c3e99f216 100644 (file)
@@ -36,6 +36,8 @@
 #define url_adapt_ext url_adapt_ext_ex
 #define url_scanner url_scanner_ex
 
+#define smart_str_0(x) ((x)->c[(x)->len] = '\0')
+
 static inline void smart_str_append(smart_str *dest, smart_str *src)
 {
        size_t newlen;
@@ -45,11 +47,11 @@ static inline void smart_str_append(smart_str *dest, smart_str *src)
        
        newlen = dest->len + src->len;
        if (newlen >= dest->a) {
-               dest->c = realloc(dest->c, newlen + 129);
+               dest->c = erealloc(dest->c, newlen + 129);
                dest->a = newlen + 128;
        }
        memcpy(dest->c + dest->len, src->c, src->len);
-       dest->c[dest->len = newlen] = '\0';
+       dest->len = newlen;
 }
 
 static inline void smart_str_appendc(smart_str *dest, char c)
@@ -58,17 +60,16 @@ static inline void smart_str_appendc(smart_str *dest, char c)
 
        newlen = dest->len + 1;
        if (newlen >= dest->a) {
-               dest->c = realloc(dest->c, newlen + 129);
+               dest->c = erealloc(dest->c, newlen + 129);
                dest->a = newlen + 128;
        }
        dest->c[dest->len++] = c;
-       dest->c[dest->len] = '\0';
 }
 
 static inline void smart_str_free(smart_str *s)
 {
        if (s->c) {
-               free(s->c);
+               efree(s->c);
                s->c = NULL;
        }
        s->a = s->len = 0;
@@ -76,9 +77,8 @@ static inline void smart_str_free(smart_str *s)
 
 static inline void smart_str_copyl(smart_str *dest, const char *src, size_t len)
 {
-       dest->c = realloc(dest->c, len + 1);
+       dest->c = erealloc(dest->c, len + 1);
        memcpy(dest->c, src, len);
-       dest->c[len] = '\0';
        dest->a = dest->len = len;
 }
 
@@ -110,7 +110,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
 {
        register const char *p, *q;
        const char *bash = NULL;
-       char sep = "?";
+       char sep = '?';
        
        q = url->c + url->len;
        
@@ -327,7 +327,6 @@ stop:
        ctx->buf.len = rest;
 }
 
-
 char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen)
 {
        char *ret;
@@ -345,9 +344,11 @@ char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char
        if (ctx->result.len == 0) {
                return strdup("");
        }
-       ret = ctx->result.c;
-       ctx->result.c = NULL;
-       ctx->result.len = ctx->result.a = 0;
+       smart_str_0(&ctx->result);
+       ret = malloc(ctx->result.len + 1);
+       memcpy(ret, ctx->result.c, ctx->result.len + 1);
+       
+       ctx->result.len = 0;
        return ret;
 }