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 register unsigned char *s = (unsigned char *) name;
11 register uint32_t hval = 0x811c9dc5;
14 hval ^= (uint32_t) *s++;
19 static inline uint32_t simple_uhash(const char *name) {
20 register unsigned char *s = (unsigned char *) name;
21 register uint32_t hval = 0x811c9dc5, c;
23 if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A';
30 static inline int str2i(const char *s) {
32 register char c, negative = (*s == '-');
34 for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) {
39 if(unlikely(negative))
45 static inline long str2l(const char *s) {
47 register char c, negative = (*s == '-');
49 for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) {
54 if(unlikely(negative))
60 static inline unsigned long str2ul(const char *s) {
61 register unsigned long n = 0;
63 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
70 static inline unsigned long long str2ull(const char *s) {
71 register unsigned long long n = 0;
73 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
80 #ifdef NETDATA_STRSAME
81 static inline int strsame(register const char *a, register const char *b) {
82 if(unlikely(a == b)) return 0;
83 while(*a && *a == *b) { a++; b++; }
87 #define strsame(a, b) strcmp(a, b)
88 #endif // NETDATA_STRSAME
90 static inline int read_single_number_file(const char *filename, unsigned long long *result) {
93 int fd = open(filename, O_RDONLY, 0666);
94 if(unlikely(fd == -1)) {
99 ssize_t r = read(fd, buffer, 30);
100 if(unlikely(r == -1)) {
108 *result = str2ull(buffer);
112 #endif //NETDATA_INLINED_H