]> arthur.barton.de Git - netdata.git/commitdiff
ARL optimization to move simple_hash() after string comparison
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 21 Jan 2017 15:25:44 +0000 (17:25 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 21 Jan 2017 15:25:44 +0000 (17:25 +0200)
src/adaptive_resortable_list.c
src/adaptive_resortable_list.h

index 3408b6268f46c1e54061ff1371266783fd633b84..b6e77cc40fa1936fa424957e0533f7698c09dafe 100644 (file)
@@ -123,9 +123,11 @@ ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst) {
     return e;
 }
 
-int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value) {
+int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, const char *value) {
     ARL_ENTRY *e;
 
+    uint32_t hash = simple_hash(s);
+
     // find if it already exists in the data
     for(e = base->head; e ; e = e->next)
         if(e->hash == hash && !strsame(e->name, s))
index f27cccfd5369dd2edcf079310c7a783b2ac8dc0a..23f63e65efcc2e59072bd696a0cf45df793b4408 100644 (file)
@@ -103,7 +103,7 @@ extern void arl_free(ARL_BASE *arl_base);
 extern ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst);
 
 // an internal call to complete the check() call
-extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value);
+extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, const char *value);
 
 // begin an ARL iteration
 extern void arl_begin(ARL_BASE *base);
@@ -115,10 +115,9 @@ extern void arl_begin(ARL_BASE *base);
 // it is defined in the header file in order to be inlined
 static inline int arl_check(ARL_BASE *base, const char *keyword, const char *value) {
     ARL_ENTRY *e = base->next_keyword;
-    uint32_t hash = simple_hash(keyword);
 
     // it should be the first entry (pointed by base->next_keyword)
-    if(likely(hash == e->hash && !strsame(keyword, e->name))) {
+    if(likely(!strsame(keyword, e->name))) {
         // it is
 
 #ifdef NETDATA_INTERNAL_CHECKS
@@ -150,7 +149,7 @@ static inline int arl_check(ARL_BASE *base, const char *keyword, const char *val
 #endif
 
     // we read from source, a not-expected keyword
-    return arl_find_or_create_and_relink(base, keyword, hash, value);
+    return arl_find_or_create_and_relink(base, keyword, value);
 }
 
 #endif //NETDATA_ADAPTIVE_RESORTABLE_LIST_H