1 #ifndef NETDATA_INLINED_H
2 #define NETDATA_INLINED_H
6 // for faster execution, allow the compiler to inline
7 // these functions that are called thousands of times per second
9 static inline uint32_t simple_hash(const char *name) {
10 unsigned char *s = (unsigned char *) name;
11 uint32_t hval = 0x811c9dc5;
14 hval ^= (uint32_t) *s++;
19 static inline uint32_t simple_uhash(const char *name) {
20 unsigned char *s = (unsigned char *) name;
21 uint32_t hval = 0x811c9dc5, c;
23 if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A';
30 static inline int simple_hash_strcmp(const char *name, const char *b, uint32_t *hash) {
31 unsigned char *s = (unsigned char *) name;
32 uint32_t hval = 0x811c9dc5;
35 if(!ret) ret = *s - *b++;
37 hval ^= (uint32_t) *s++;
43 static inline int str2i(const char *s) {
45 char c, negative = (*s == '-');
47 for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) {
52 if(unlikely(negative))
58 static inline long str2l(const char *s) {
60 char c, negative = (*s == '-');
62 for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) {
67 if(unlikely(negative))
73 static inline unsigned long str2ul(const char *s) {
76 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
83 static inline unsigned long long str2ull(const char *s) {
84 unsigned long long n = 0;
86 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
93 #ifdef NETDATA_STRCMP_OVERRIDE
94 static inline int strcmp(const char *a, const char *b) {
95 if(unlikely(a == b)) return 0;
96 while(*a && *a == *b) { a++; b++; }
99 #endif // NETDATA_STRSAME
101 static inline int read_single_number_file(const char *filename, unsigned long long *result) {
104 int fd = open(filename, O_RDONLY, 0666);
105 if(unlikely(fd == -1)) {
110 ssize_t r = read(fd, buffer, 30);
111 if(unlikely(r == -1)) {
119 *result = str2ull(buffer);
123 #endif //NETDATA_INLINED_H