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 static inline int read_single_number_file(const char *filename, unsigned long long *result) {
81 char buffer[1024 + 1];
83 int fd = open(filename, O_RDONLY, 0666);
84 if(unlikely(fd == -1)) {
89 ssize_t r = read(fd, buffer, 1024);
90 if(unlikely(r == -1)) {
97 *result = str2ull(buffer);
101 #endif //NETDATA_INLINED_H