1 #ifndef NETDATA_INLINED_H
2 #define NETDATA_INLINED_H
7 // GCC extension to define a function as a preprocessor macro
9 #define simple_hash(name) ({ \
10 register unsigned char *__hash_source = (unsigned char *)(name); \
11 register uint32_t __hash_value = 0x811c9dc5; \
12 while (*__hash_source) { \
13 __hash_value *= 16777619; \
14 __hash_value ^= (uint32_t) *__hash_source++; \
19 #define simple_uhash(name) ({ \
20 register unsigned char *__hash_source = (unsigned char *)(name); \
21 register uint32_t __hash_value = 0x811c9dc5, __hash_char; \
22 while ((__hash_char = *__hash_source++)) { \
23 if (unlikely(__hash_char >= 'A' && __hash_char <= 'Z')) \
24 __hash_char += 'a' - 'A'; \
25 __hash_value *= 16777619; \
26 __hash_value ^= __hash_char; \
31 #else /* ! HAVE_STMT_EXPR */
33 // for faster execution, allow the compiler to inline
34 // these functions that are called to hash strings
35 static inline uint32_t simple_hash(const char *name) {
36 register unsigned char *s = (unsigned char *) name;
37 register uint32_t hval = 0x811c9dc5;
40 hval ^= (uint32_t) *s++;
45 static inline uint32_t simple_uhash(const char *name) {
46 register unsigned char *s = (unsigned char *) name;
47 register uint32_t hval = 0x811c9dc5, c;
49 if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A';
56 #endif /* HAVE_STMT_EXPR */
58 static inline int read_single_number_file(const char *filename, unsigned long long *result) {
59 char buffer[1024 + 1];
61 int fd = open(filename, O_RDONLY, 0666);
62 if(unlikely(fd == -1)) {
67 ssize_t r = read(fd, buffer, 1024);
68 if(unlikely(r == -1)) {
75 *result = strtoull(buffer, NULL, 0);
79 #endif //NETDATA_INLINED_H