diff options
author | Davi Arnaut <davi@apache.org> | 2007-06-30 22:48:52 +0000 |
---|---|---|
committer | Davi Arnaut <davi@apache.org> | 2007-06-30 22:48:52 +0000 |
commit | 8e8fdb279b054f6c0e2c993af540b1e2478cdd93 (patch) | |
tree | 7f0a6c2a6e04a0eb2ce28d4895da736455edcfa4 | |
parent | 728dc1a0f21a68acdc5b02744ca12c9cc9aaae88 (diff) | |
download | apr-8e8fdb279b054f6c0e2c993af540b1e2478cdd93.tar.gz |
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.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@552223 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | include/apr_tables.h | 11 | ||||
-rw-r--r-- | tables/apr_tables.c | 14 |
3 files changed, 28 insertions, 0 deletions
@@ -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 diff --git a/include/apr_tables.h b/include/apr_tables.h index 11213a549..a2f450ea8 100644 --- a/include/apr_tables.h +++ b/include/apr_tables.h @@ -232,6 +232,17 @@ APR_DECLARE(apr_table_t *) apr_table_copy(apr_pool_t *p, 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 */ diff --git a/tables/apr_tables.c b/tables/apr_tables.c index 9a25e366e..51b23407c 100644 --- a/tables/apr_tables.c +++ b/tables/apr_tables.c @@ -423,6 +423,20 @@ APR_DECLARE(apr_table_t *) apr_table_copy(apr_pool_t *p, const apr_table_t *t) 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; |