summaryrefslogtreecommitdiff
path: root/tables
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2015-03-11 17:54:48 +0000
committerYann Ylavic <ylavic@apache.org>2015-03-11 17:54:48 +0000
commita19d7e5ce9b457b1879ed13e2d2e1faa5b0ef3ed (patch)
tree84c08f1f8058368ff2d375e00ffd5803a449a265 /tables
parentd52f041692a4dd7d647366cab5fcadce14704691 (diff)
downloadapr-a19d7e5ce9b457b1879ed13e2d2e1faa5b0ef3ed.tar.gz
apr_hash: introduce apr_hash_get_or_set().
Allows to get an entry, or if it does not exist set a new one in the same pass. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1665952 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tables')
-rw-r--r--tables/apr_hash.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tables/apr_hash.c b/tables/apr_hash.c
index 0bf4d28c2..d4567710d 100644
--- a/tables/apr_hash.c
+++ b/tables/apr_hash.c
@@ -399,6 +399,25 @@ APR_DECLARE(void) apr_hash_set(apr_hash_t *ht,
/* else key not present and val==NULL */
}
+APR_DECLARE(void *) apr_hash_get_or_set(apr_hash_t *ht,
+ const void *key,
+ apr_ssize_t klen,
+ const void *val)
+{
+ apr_hash_entry_t **hep;
+ hep = find_entry(ht, key, klen, val);
+ if (*hep) {
+ val = (*hep)->val;
+ /* check that the collision rate isn't too high */
+ if (ht->count > ht->max) {
+ expand_array(ht);
+ }
+ return (void *)val;
+ }
+ /* else key not present and val==NULL */
+ return NULL;
+}
+
APR_DECLARE(unsigned int) apr_hash_count(apr_hash_t *ht)
{
return ht->count;