summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Leggett <minfrin@apache.org>2016-03-07 23:36:23 +0000
committerGraham Leggett <minfrin@apache.org>2016-03-07 23:36:23 +0000
commit4316b99199f505ac8eb15fcebb39e54518efe521 (patch)
tree049e53640a8745a5620b883a4a92bac0fe6edf9a
parentc0cf341d9d232bad5e5e4e70a4885ef9220b197a (diff)
downloadapr-4316b99199f505ac8eb15fcebb39e54518efe521.tar.gz
apr_table_overlap: Add APR_OVERLAP_TABLES_ADD to merge and set when
overlapping tables. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1734004 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES3
-rw-r--r--include/apr_tables.h9
-rw-r--r--tables/apr_tables.c4
-rw-r--r--test/testtable.c24
4 files changed, 39 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 26cd40031..91a205055 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes for APR 2.0.0
+ *) apr_table_overlap: Add APR_OVERLAP_TABLES_ADD to merge and set when
+ overlapping tables. [Graham Leggett]
+
*) apr_proc/global_mutex: Fix API regarding the native OS mutexes
accessors from/to available APR mechanisms, adding the new functions
apr_os_proc_mutex_get_ex() and apr_os_proc_mutex_set_ex() which give
diff --git a/include/apr_tables.h b/include/apr_tables.h
index 194af02f2..c100f42d2 100644
--- a/include/apr_tables.h
+++ b/include/apr_tables.h
@@ -436,6 +436,8 @@ APR_DECLARE(int) apr_table_vdo(apr_table_do_callback_fn_t *comp,
#define APR_OVERLAP_TABLES_SET (0)
/** flag for overlap to use apr_table_mergen */
#define APR_OVERLAP_TABLES_MERGE (1)
+/** flag for overlap to use apr_table_addn */
+#define APR_OVERLAP_TABLES_ADD (2)
/**
* For each element in table b, either use setn or mergen to add the data
* to table a. Which method is used is determined by the flags passed in.
@@ -444,6 +446,7 @@ APR_DECLARE(int) apr_table_vdo(apr_table_do_callback_fn_t *comp,
* @param flags How to add the table to table a. One of:
* APR_OVERLAP_TABLES_SET Use apr_table_setn
* APR_OVERLAP_TABLES_MERGE Use apr_table_mergen
+ * APR_OVERLAP_TABLES_ADD Use apr_table_addn
* @remark When merging duplicates, the two values are concatenated,
* separated by the string ", ".
* @remark This function is highly optimized, and uses less memory and CPU cycles
@@ -461,6 +464,9 @@ APR_DECLARE(int) apr_table_vdo(apr_table_do_callback_fn_t *comp,
* if (flags & APR_OVERLAP_TABLES_MERGE) {
* apr_table_mergen(a, belt[i].key, belt[i].val);
* }
+ * else if (flags & APR_OVERLAP_TABLES_ADD) {
+ * apr_table_addn(a, belt[i].key, belt[i].val);
+ * }
* else {
* apr_table_setn(a, belt[i].key, belt[i].val);
* }
@@ -484,7 +490,8 @@ APR_DECLARE(void) apr_table_overlap(apr_table_t *a, const apr_table_t *b,
*
* @param t Table.
* @param flags APR_OVERLAP_TABLES_MERGE to merge, or
- * APR_OVERLAP_TABLES_SET to overwrite
+ * APR_OVERLAP_TABLES_SET to overwrite, or
+ * APR_OVERLAP_TABLES_ADD to add
* @remark When merging duplicates, the two values are concatenated,
* separated by the string ", ".
*/
diff --git a/tables/apr_tables.c b/tables/apr_tables.c
index 2f5b4e537..6d9aff881 100644
--- a/tables/apr_tables.c
+++ b/tables/apr_tables.c
@@ -1103,6 +1103,10 @@ APR_DECLARE(void) apr_table_compress(apr_table_t *t, unsigned flags)
int i;
int dups_found;
+ if (flags == APR_OVERLAP_TABLES_ADD) {
+ return;
+ }
+
if (t->a.nelts <= 1) {
return;
}
diff --git a/test/testtable.c b/test/testtable.c
index d24053edb..0a9960f12 100644
--- a/test/testtable.c
+++ b/test/testtable.c
@@ -199,6 +199,29 @@ static void table_overlap2(abts_case *tc, void *data)
}
+static void table_overlap3(abts_case *tc, void *data)
+{
+ apr_pool_t *subp;
+ apr_table_t *t1, *t2;
+
+ apr_pool_create(&subp, p);
+
+ t1 = apr_table_make(subp, 1);
+ t2 = apr_table_make(p, 1);
+ apr_table_addn(t1, "t1", "one");
+ apr_table_addn(t1, "t1", "overlay");
+ apr_table_addn(t2, "t2", "two");
+ apr_table_addn(t2, "t2", "overlay");
+
+ apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_ADD);
+
+ ABTS_INT_EQUAL(tc, 4, apr_table_elts(t1)->nelts);
+
+ ABTS_STR_EQUAL(tc, "one", apr_table_get(t1, "t1"));
+ ABTS_STR_EQUAL(tc, "two", apr_table_get(t1, "t2"));
+
+}
+
abts_suite *testtable(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -215,6 +238,7 @@ abts_suite *testtable(abts_suite *suite)
abts_run_test(suite, table_unset, NULL);
abts_run_test(suite, table_overlap, NULL);
abts_run_test(suite, table_overlap2, NULL);
+ abts_run_test(suite, table_overlap3, NULL);
return suite;
}