apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r552223 - in /apr/apr/trunk: CHANGES include/apr_tables.h tables/apr_tables.c
Date Sat, 30 Jun 2007 22:48:53 GMT
Author: davi
Date: Sat Jun 30 15:48:52 2007
New Revision: 552223

URL: http://svn.apache.org/viewvc?view=rev&rev=552223
Log:
Add table cloning (deep copy) convenience function named apr_table_clone().
The function copies all fields of the table, and makes copies of dynamically
allocated memory pointed to by the fields.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_tables.h
    apr/apr/trunk/tables/apr_tables.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?view=diff&rev=552223&r1=552222&r2=552223
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Sat Jun 30 15:48:52 2007
@@ -1,5 +1,8 @@
 Changes for APR 1.3.0
 
+  *) Add table cloning (deep copy) convenience function.
+     [Davi Arnaut]
+
   *) Rework the WIN32 CV code to signal the condition only if one or
      more threads are blocked on the condition variable. If no threads
      are waiting on the condition variable, nothing happens. The change

Modified: apr/apr/trunk/include/apr_tables.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_tables.h?view=diff&rev=552223&r1=552222&r2=552223
==============================================================================
--- apr/apr/trunk/include/apr_tables.h (original)
+++ apr/apr/trunk/include/apr_tables.h Sat Jun 30 15:48:52 2007
@@ -232,6 +232,17 @@
                                           const apr_table_t *t);
 
 /**
+ * Create a new table whose contents are deep copied from the given
+ * table. A deep copy operation copies all fields, and makes copies
+ * of dynamically allocated memory pointed to by the fields.
+ * @param p The pool to allocate the new table out of
+ * @param t The table to clone
+ * @return A deep copy of the table passed in
+ */
+APR_DECLARE(apr_table_t *) apr_table_clone(apr_pool_t *p,
+                                           const apr_table_t *t);
+
+/**
  * Delete all of the elements from a table
  * @param t The table to clear
  */

Modified: apr/apr/trunk/tables/apr_tables.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_tables.c?view=diff&rev=552223&r1=552222&r2=552223
==============================================================================
--- apr/apr/trunk/tables/apr_tables.c (original)
+++ apr/apr/trunk/tables/apr_tables.c Sat Jun 30 15:48:52 2007
@@ -423,6 +423,20 @@
     return new;
 }
 
+APR_DECLARE(apr_table_t *) apr_table_clone(apr_pool_t *p, const apr_table_t *t)
+{
+    const apr_array_header_t *array = apr_table_elts(t);
+    apr_table_entry_t *elts = (apr_table_entry_t *) array->elts;
+    apr_table_t *new = apr_table_make(p, array->nelts);
+    int i;
+
+    for (i = 0; i < array->nelts; i++) {
+        apr_table_add(new, elts[i].key, elts[i].val);
+    }
+
+    return new;
+}
+
 static void table_reindex(apr_table_t *t)
 {
     int i;



Mime
View raw message