From add01998e4e874ca4432c8e1e6589388a3c440c8 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 23 Feb 2021 00:00:00 -0600 Subject: [PATCH] library: tweaked key used in hash table, api This small change was a result of some experimentation trading our current 'hsearch' hash scheme for 'gperf'. I discovered that when the ':' character was a part of each 'gperf' key, that generated search logic was more complicated and thus slower. But without a ':', it was a little cleaner/leaner and therefore slightly faster. Assuming that the same trailing ':' *might* affect the current 'hsearch' logic, to be safe we will remove it. [ while the 'gperf' version will slightly outperform ] [ an 'hsearch', too many ugly implementation details ] [ were exposed which complicates future maintenance. ] [ thus, we'll retain our current 'hsearch' approach. ] Signed-off-by: Jim Warner --- proc/meminfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proc/meminfo.c b/proc/meminfo.c index e6f13640..998858ca 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -542,9 +542,9 @@ static inline int meminfo_items_check_failed ( static int meminfo_make_hash_failed ( struct meminfo_info *info) { - #define htVAL(f) e.key = STRINGIFY(f) ":"; e.data = &info->hist.new. f; \ + #define htVAL(f) e.key = STRINGIFY(f); e.data = &info->hist.new. f; \ if (!hsearch_r(e, ENTER, &ep, &info->hashtab)) return 1; - #define htXTRA(k,f) e.key = STRINGIFY(k) ":"; e.data = &info->hist.new. f; \ + #define htXTRA(k,f) e.key = STRINGIFY(k); e.data = &info->hist.new. f; \ if (!hsearch_r(e, ENTER, &ep, &info->hashtab)) return 1; ENTRY e, *ep; size_t n; @@ -672,7 +672,7 @@ static int meminfo_read_failed ( static ENTRY e; // just to keep coverity off our backs (e.data) ENTRY *ep; - if (!(tail = strchr(head, ' '))) + if (!(tail = strchr(head, ':'))) break; *tail = '\0'; valptr = NULL;