From 99de1d0479c35229acf01feeabfe4e7c8c3dd7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Fri, 7 Jun 2019 10:58:20 +0200 Subject: [PATCH] MINOR: dict: Store the length of the dictionary entries. 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 | 1 + src/dict.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/types/dict.h b/include/types/dict.h index 9e4f41a68..006e91524 100644 --- a/include/types/dict.h +++ b/include/types/dict.h @@ -7,6 +7,7 @@ struct dict_entry { struct ebpt_node value; unsigned int refcount; + size_t len; }; struct dict { diff --git a/src/dict.c b/src/dict.c index 777530a20..c2580e179 100644 --- a/src/dict.c +++ b/src/dict.c @@ -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; }