apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davi Arnaut <d...@haxent.com.br>
Subject [patch 7/9] share apr_file_t buffers
Date Fri, 27 Apr 2007 14:29:25 GMT
Share buffers for files opened from the same pool. This may a few KBs for
code paths like:

apr_file_open(f, p);
read/write
apr_file_close(f);

apr_file_open(f, p);
read/write
apr_file_close(f);

---
 srclib/apr/file_io/unix/open.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Index: 2.2.x/srclib/apr/file_io/unix/open.c
===================================================================
--- 2.2.x.orig/srclib/apr/file_io/unix/open.c	2007-04-27 11:09:48.000000000 -0300
+++ 2.2.x/srclib/apr/file_io/unix/open.c	2007-04-27 11:09:51.000000000 -0300
@@ -26,6 +26,8 @@
 #include "fsio.h"
 #endif
 
+static const char file_cache_buffer_key[] = "FILE_CACHE_BUFFER";
+
 apr_status_t apr_unix_file_cleanup(void *thefile)
 {
     apr_file_t *file = thefile;
@@ -34,6 +36,8 @@
     if (file->buffered) {
         /* XXX: flush here is not mutex protected */
         flush_rv = apr_file_flush(file);
+        apr_pool_userdata_setn(file->buffer, file_cache_buffer_key,
+                               apr_pool_cleanup_null, file->pool);
     }
     if (close(file->filedes) == 0) {
         file->filedes = -1;
@@ -151,7 +155,18 @@
     (*new)->buffered = (flag & APR_BUFFERED) > 0;
 
     if ((*new)->buffered) {
-        (*new)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
+        void *buffer = NULL;
+
+        apr_pool_userdata_get(&buffer, file_cache_buffer_key, pool);
+
+        if (!buffer) {
+            buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
+        }
+        else {
+            apr_pool_userdata_setn(NULL, file_cache_buffer_key,
+                                   apr_pool_cleanup_null, pool);
+        }
+        (*new)->buffer = buffer;
         (*new)->bufsize = APR_FILE_DEFAULT_BUFSIZE;
 #if APR_HAS_THREADS
         if ((*new)->flags & APR_XTHREAD) {

--

Mime
View raw message