apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject [PATCH] simplify apr_pools.c a little
Date Wed, 29 Oct 2003 21:52:46 GMT
I wrote this when tracking down that psprintf bug, I think it makes the
code a little clearer than trying to follow the pointer juggling
everywhere.  Any objections to committing it? (object code is
byte-for-byte identical before and after)

 apr_pools.c |   63 ++++++++++++++++++++++++------------------------------------
 1 files changed, 26 insertions(+), 37 deletions(-)
Index: memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.200
diff -u -r1.200 apr_pools.c
--- memory/unix/apr_pools.c	28 Sep 2003 16:43:44 -0000	1.200
+++ memory/unix/apr_pools.c	29 Oct 2003 21:48:53 -0000
@@ -615,6 +615,21 @@
 }
 #endif /* defined(NETWARE) */
 
+/* Node list management helper macros; list_insert() inserts 'node'
+ * before 'point'. */
+#define list_insert(node, point) do {           \
+    node->ref = point->ref;                     \
+    *node->ref = node;                          \
+    node->next = point;                         \
+    point->ref = &node->next;                   \
+} while (0) 
+
+/* list_remove() removes 'node' from its list. */
+#define list_remove(node) do {                  \
+    *node->ref = node->next;                    \
+    node->next->ref = node->ref;                \
+} while (0)
+
 /*
  * Memory allocation
  */
@@ -638,8 +653,7 @@
 
     node = active->next;
     if (size < (apr_size_t)(node->endp - node->first_avail)) {
-        *node->ref = node->next;
-        node->next->ref = node->ref;
+        list_remove(node);
     }
     else {
         if ((node = allocator_alloc(pool->allocator, size)) == NULL) {
@@ -655,10 +669,7 @@
     mem = node->first_avail;
     node->first_avail += size;
 
-    node->ref = active->ref;
-    *node->ref = node;
-    node->next = active;
-    active->ref = &node->next;
+    list_insert(node, active);
 
     pool->active = node;
 
@@ -675,13 +686,8 @@
     }
     while (free_index < node->free_index);
 
-    *active->ref = active->next;
-    active->next->ref = active->ref;
-
-    active->ref = node->ref;
-    *active->ref = active;
-    active->next = node;
-    node->ref = &active->next;
+    list_remove(active);
+    list_insert(active, node);
 
     return mem;
 }
@@ -944,13 +950,9 @@
     node = active->next;
     if (!ps->got_a_new_node
         && size < (apr_size_t)(node->endp - node->first_avail)) {
-        *node->ref = node->next;
-        node->next->ref = node->ref;
 
-        node->ref = active->ref;
-        *node->ref = node;
-        node->next = active;
-        active->ref = &node->next;
+        list_remove(node);
+        list_insert(node, active);
 
         node->free_index = 0;
 
@@ -967,13 +969,8 @@
             }
             while (free_index < node->free_index);
 
-            *active->ref = active->next;
-            active->next->ref = active->ref;
-
-            active->ref = node->ref;
-            *active->ref = active;
-            active->next = node;
-            node->ref = &active->next;
+            list_remove(active);
+            list_insert(active, node);
         }
 
         node = pool->active;
@@ -1058,10 +1055,7 @@
 
     node->free_index = 0;
 
-    node->ref = active->ref;
-    *node->ref = node;
-    node->next = active;
-    active->ref = &node->next;
+    list_insert(node, active);
 
     pool->active = node;
 
@@ -1079,13 +1073,8 @@
     }
     while (free_index < node->free_index);
 
-    *active->ref = active->next;
-    active->next->ref = active->ref;
-
-    active->ref = node->ref;
-    *active->ref = active;
-    active->next = node;
-    node->ref = &active->next;
+    list_remove(active);
+    list_insert(active, node);
 
     return strp;
 }

Mime
View raw message