X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Finlined.h;h=0dc11c950951b3d9dfcf4bda8a8fd615cc5be058;hb=0444aa8ff91dce4d4ab5971187944ed894b550e2;hp=2b41b66a5e78717a4439f2c3c913e748f198dbf0;hpb=ce131c3247ca96b100e8c21ea9e9ab2f0a25da25;p=netdata.git diff --git a/src/inlined.h b/src/inlined.h index 2b41b66a..0dc11c95 100644 --- a/src/inlined.h +++ b/src/inlined.h @@ -3,12 +3,25 @@ #include "common.h" +#ifdef KERNEL_32BIT +typedef uint32_t kernel_uint_t; +#define str2kernel_uint_t(string) str2uint32_t(string) +#define KERNEL_UINT_FORMAT "%u" +#else +typedef uint64_t kernel_uint_t; +#define str2kernel_uint_t(string) str2uint64_t(string) +#define KERNEL_UINT_FORMAT "%" PRIu64 +#endif + +#define str2pid_t(string) str2uint32_t(string) + + // for faster execution, allow the compiler to inline // these functions that are called thousands of times per second static inline uint32_t simple_hash(const char *name) { - register unsigned char *s = (unsigned char *) name; - register uint32_t hval = 0x811c9dc5; + unsigned char *s = (unsigned char *) name; + uint32_t hval = 0x811c9dc5; while (*s) { hval *= 16777619; hval ^= (uint32_t) *s++; @@ -17,8 +30,8 @@ static inline uint32_t simple_hash(const char *name) { } static inline uint32_t simple_uhash(const char *name) { - register unsigned char *s = (unsigned char *) name; - register uint32_t hval = 0x811c9dc5, c; + unsigned char *s = (unsigned char *) name; + uint32_t hval = 0x811c9dc5, c; while ((c = *s++)) { if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A'; hval *= 16777619; @@ -27,9 +40,22 @@ static inline uint32_t simple_uhash(const char *name) { return hval; } +static inline int simple_hash_strcmp(const char *name, const char *b, uint32_t *hash) { + unsigned char *s = (unsigned char *) name; + uint32_t hval = 0x811c9dc5; + int ret = 0; + while (*s) { + if(!ret) ret = *s - *b++; + hval *= 16777619; + hval ^= (uint32_t) *s++; + } + *hash = hval; + return ret; +} + static inline int str2i(const char *s) { - register int n = 0; - register char c, negative = (*s == '-'); + int n = 0; + char c, negative = (*s == '-'); for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) { n *= 10; @@ -43,8 +69,8 @@ static inline int str2i(const char *s) { } static inline long str2l(const char *s) { - register long n = 0; - register char c, negative = (*s == '-'); + long n = 0; + char c, negative = (*s == '-'); for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) { n *= 10; @@ -57,9 +83,29 @@ static inline long str2l(const char *s) { return n; } +static inline uint32_t str2uint32_t(const char *s) { + uint32_t n = 0; + char c; + for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) { + n *= 10; + n += c - '0'; + } + return n; +} + +static inline uint64_t str2uint64_t(const char *s) { + uint64_t n = 0; + char c; + for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) { + n *= 10; + n += c - '0'; + } + return n; +} + static inline unsigned long str2ul(const char *s) { - register unsigned long n = 0; - register char c; + unsigned long n = 0; + char c; for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) { n *= 10; n += c - '0'; @@ -68,8 +114,8 @@ static inline unsigned long str2ul(const char *s) { } static inline unsigned long long str2ull(const char *s) { - register unsigned long long n = 0; - register char c; + unsigned long long n = 0; + char c; for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) { n *= 10; n += c - '0'; @@ -77,15 +123,29 @@ static inline unsigned long long str2ull(const char *s) { return n; } -#ifdef NETDATA_STRSAME -static inline int strsame(register const char *a, register const char *b) { +#ifdef NETDATA_STRCMP_OVERRIDE +#ifdef strcmp +#undef strcmp +#endif +#define strcmp(a, b) strsame(a, b) +#endif // NETDATA_STRCMP_OVERRIDE + +static inline int strsame(const char *a, const char *b) { if(unlikely(a == b)) return 0; while(*a && *a == *b) { a++; b++; } return *a - *b; } -#else -#define strsame(a, b) strcmp(a, b) -#endif // NETDATA_STRSAME + +static inline char *strncpyz(char *dst, const char *src, size_t n) { + char *p = dst; + + while (*src && n--) + *dst++ = *src++; + + *dst = '\0'; + + return p; +} static inline int read_single_number_file(const char *filename, unsigned long long *result) { char buffer[30 + 1];