]> granicus.if.org Git - procps-ng/commitdiff
library: tweaked key used in hash table, <meminfo> api
authorJim Warner <james.warner@comcast.net>
Tue, 23 Feb 2021 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Sun, 28 Feb 2021 10:18:26 +0000 (21:18 +1100)
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 <james.warner@comcast.net>
proc/meminfo.c

index e6f13640bd95d4713a39ddba17481e9ea71d23e1..998858ca9058b810cba0629a6f82e57d230812a7 100644 (file)
@@ -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;