@cryptotaxi247 / netdata-1 / commits / a0fde901c

ARL optimization to move simple_hash() after string comparison

Costa Tsaousis (ktsaou) committed Jan 21, 2017 at 17:25 UTC a0fde901ce242612dd6208ce8a942542c78660ec
2 files changed +6 -5
src/adaptive_resortable_list.c
+3 -1
@@ -123,9 +123,11 @@ ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst) {
123 return e;
124 }
125
126 -int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value) {
126 +int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, const char *value) {
127 ARL_ENTRY *e;
128
129 + uint32_t hash = simple_hash(s);
130 +
131 // find if it already exists in the data
132 for(e = base->head; e ; e = e->next)
133 if(e->hash == hash && !strsame(e->name, s))
src/adaptive_resortable_list.h
+3 -4
@@ -103,7 +103,7 @@ extern void arl_free(ARL_BASE *arl_base);
103 extern ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst);
104
105 // an internal call to complete the check() call
106 -extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value);
106 +extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, const char *value);
107
108 // begin an ARL iteration
109 extern void arl_begin(ARL_BASE *base);
@@ -115,10 +115,9 @@ extern void arl_begin(ARL_BASE *base);
115 // it is defined in the header file in order to be inlined
116 static inline int arl_check(ARL_BASE *base, const char *keyword, const char *value) {
117 ARL_ENTRY *e = base->next_keyword;
118 - uint32_t hash = simple_hash(keyword);
118
119 // it should be the first entry (pointed by base->next_keyword)
121 - if(likely(hash == e->hash && !strsame(keyword, e->name))) {
120 + if(likely(!strsame(keyword, e->name))) {
121 // it is
122
123 #ifdef NETDATA_INTERNAL_CHECKS
@@ -150,7 +149,7 @@ static inline int arl_check(ARL_BASE *base, const char *keyword, const char *val
149 #endif
150
151 // we read from source, a not-expected keyword
153 - return arl_find_or_create_and_relink(base, keyword, hash, value);
152 + return arl_find_or_create_and_relink(base, keyword, value);
153 }
154
155 #endif //NETDATA_ADAPTIVE_RESORTABLE_LIST_H