]> granicus.if.org Git - apache/commitdiff
Optimization: modified the power-of-two allocator in ap_rgetline_core()
authorBrian Pane <brianp@apache.org>
Mon, 13 May 2002 06:16:31 +0000 (06:16 +0000)
committerBrian Pane <brianp@apache.org>
Mon, 13 May 2002 06:16:31 +0000 (06:16 +0000)
so that it converges on the new buffer size in a single iteration.

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

server/protocol.c

index 499224508f009d1e0445dfee7ecda9f1eda1fe3a..f3765eefd9e503379a3a4b956e39801d88a8f2b9 100644 (file)
@@ -303,13 +303,13 @@ AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
                 *s = apr_palloc(r->pool, len);
             }
             else if (bytes_handled + len > current_alloc) {
-                /* We resize to the next power of 2. */
-                apr_size_t new_size = current_alloc;
+                /* Increase the buffer size */
+                apr_size_t new_size = current_alloc * 2;
                 char *new_buffer;
 
-                do {
-                    new_size *= 2;
-                } while (bytes_handled + len > new_size);
+                if (bytes_handled + len > new_size) {
+                    new_size = (bytes_handled + len) * 2;
+                }
 
                 new_buffer = apr_palloc(r->pool, new_size);