]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dict: Store the length of the dictionary entries.
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 7 Jun 2019 08:58:20 +0000 (10:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 7 Jun 2019 13:47:54 +0000 (15:47 +0200)
When allocating new dictionary entries we store the length of the strings.
May be useful so that not to have to call strlen() too much often at runing
time.

include/types/dict.h
src/dict.c

index 9e4f41a68b4ac6c3eddc2aa818313cf2120386ef..006e91524db414ee1208a955725859c5234661ac 100644 (file)
@@ -7,6 +7,7 @@
 struct dict_entry {
        struct ebpt_node value;
        unsigned int refcount;
+       size_t len;
 };
 
 struct dict {
index 777530a20cee6472575b9abc7d3c0304cf99ddc5..c2580e1793704e95c12dfe6cc0ec9640a295d221 100644 (file)
@@ -36,6 +36,7 @@ static struct dict_entry *new_dict_entry(char *s)
        if (!de->value.key)
                goto err;
 
+       de->len = strlen(s);
        de->refcount = 1;
 
        return de;
@@ -43,6 +44,7 @@ static struct dict_entry *new_dict_entry(char *s)
  err:
        free(de->value.key);
        de->value.key = NULL;
+       de->len = 0;
        free(de);
        return NULL;
 }