]> granicus.if.org Git - apache/commitdiff
Optimization for ap_rgetline_core(): When "folding" mode is enabled,
authorBrian Pane <brianp@apache.org>
Mon, 1 Jul 2002 05:05:51 +0000 (05:05 +0000)
committerBrian Pane <brianp@apache.org>
Mon, 1 Jul 2002 05:05:51 +0000 (05:05 +0000)
clear and re-use the temporary brigade rather than destroying it
and creating a new one

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95920 13f79535-47bb-0310-9956-ffa450edef68

server/protocol.c

index ed7b1972656c0d2089bad7017f0ea9897249581f..59119846e306d83be2a022da0e64f9f466b90599 100644 (file)
@@ -335,9 +335,6 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
         bytes_handled += len;
     }
 
-    /* We no longer need the returned brigade. */
-    apr_brigade_destroy(b);
-
     /* We likely aborted early before reading anything or we read no
      * data.  Technically, this might be success condition.  But,
      * probably means something is horribly wrong.  For now, we'll
@@ -345,6 +342,7 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
      */
     if (bytes_handled == 0) {
         *read = 0;
+        apr_brigade_destroy(b);
         return APR_SUCCESS;
     }
 
@@ -370,6 +368,7 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
             rv = ap_rgetline_core(&tmp, next_size, &next_len, r, fold);
 
             if (rv != APR_SUCCESS) {
+                apr_brigade_destroy(b);
                 return rv;
             }
 
@@ -398,6 +397,7 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
             last_char = *s + bytes_handled - 1;
         }
         else {
+            apr_brigade_destroy(b);
             return APR_ENOSPC;
         }
     }
@@ -438,41 +438,40 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
      */
     if (fold && bytes_handled && !saw_eos) {
         const char *str;
-        apr_bucket_brigade *bb;
         apr_size_t len;
         char c;
 
-        /* Create a brigade for this filter read. */
-        bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
+        /* Clear the temp brigade for this filter read. */
+        apr_brigade_cleanup(b);
 
         /* We only care about the first byte. */
-        rv = ap_get_brigade(r->input_filters, bb, AP_MODE_SPECULATIVE,
+        rv = ap_get_brigade(r->input_filters, b, AP_MODE_SPECULATIVE,
                             APR_BLOCK_READ, 1);
 
         if (rv != APR_SUCCESS) {
-            apr_brigade_destroy(bb);
+            apr_brigade_destroy(b);
             return rv;
         }
 
-        if (APR_BRIGADE_EMPTY(bb)) {
+        if (APR_BRIGADE_EMPTY(b)) {
             *read = bytes_handled;
-            apr_brigade_destroy(bb);
+            apr_brigade_destroy(b);
             return APR_SUCCESS;
         }
 
-        e = APR_BRIGADE_FIRST(bb);
+        e = APR_BRIGADE_FIRST(b);
 
         /* If we see an EOS, don't bother doing anything more. */
         if (APR_BUCKET_IS_EOS(e)) {
             *read = bytes_handled;
-            apr_brigade_destroy(bb);
+            apr_brigade_destroy(b);
             return APR_SUCCESS;
         }
 
         rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);
 
         if (rv != APR_SUCCESS) {
-            apr_brigade_destroy(bb);
+            apr_brigade_destroy(b);
             return rv;
         }
 
@@ -482,9 +481,6 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
          */
         c = *str;
 
-        /* We no longer need the returned brigade. */
-        apr_brigade_destroy(bb);
-
         /* Found one, so call ourselves again to get the next line.
          *
          * FIXME: If the folding line is completely blank, should we
@@ -512,6 +508,7 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
                 rv = ap_rgetline_core(&tmp, next_size, &next_len, r, fold);
 
                 if (rv != APR_SUCCESS) {
+                    apr_brigade_destroy(b);
                     return rv;
                 }
 
@@ -531,15 +528,18 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
                 }
 
                 *read = bytes_handled + next_len;
+                apr_brigade_destroy(b);
                 return APR_SUCCESS;
             }
             else {
+                apr_brigade_destroy(b);
                 return APR_ENOSPC;
             }
         }
     }
 
     *read = bytes_handled;
+    apr_brigade_destroy(b);
     return APR_SUCCESS;
 }