X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=hash.c;h=9aba831623a167d5a0ed32f7f54a326de8490cf5;hb=ff37abb0c7c60481e1264914fa5e02e9986c5cd9;hp=e136d108831c47ff061a9b55e14f47887160851c;hpb=1a8bb31d2a122010e99e47ce238a99f1cd922379;p=xonotic%2Fgmqcc.git diff --git a/hash.c b/hash.c index e136d10..9aba831 100644 --- a/hash.c +++ b/hash.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, 2013, 2014 + * Copyright (C) 2012, 2013, 2014, 2015 * Dale Weiler * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -301,32 +301,36 @@ static GMQCC_FORCEINLINE uint32_t hash_murmur(const void *GMQCC_RESTRICT key, si #define STRLEN_ONES ((size_t)-1/UCHAR_MAX) #define STRLEN_HIGHS (STRLEN_ONES * (UCHAR_MAX/2+1)) #define STRLEN_HASZERO(X) (((X)-STRLEN_ONES) & ~(X) & STRLEN_HIGHS) -ASAN_DISABLE size_t hash(const char *key) { + +static ASAN_DISABLE size_t hash_strlen(const char *key) { const char *s = key; const char *a = s; const size_t *w; for (; (uintptr_t)s % STRLEN_ALIGN; s++) { - if (!*s) - return hash_murmur((const void *)key, s-a); + if (*s) + continue; + return s-a; } VALGRIND_MAKE_MEM_DEFINED(s, STRLEN_ALIGN); - for (w = (const void *)s; !STRLEN_HASZERO(*w); w++) { + for (w = (const size_t *)s; !STRLEN_HASZERO(*w); w++) { /* Make the next word legal to access */ VALGRIND_MAKE_MEM_DEFINED(w + STRLEN_ALIGN, STRLEN_ALIGN); } - for (s = (const void *)w; *s; s++); + for (s = (const char *)w; *s; s++); /* It's not legal to access this area anymore */ VALGRIND_MAKE_MEM_NOACCESS(s + 1, STRLEN_ALIGN); - - return hash_murmur((const void *)key, s-a); + return s-a; } #else -/* No way to disable asan instrumenting, use strlen. */ +static GMQCC_INLINE size_t hash_strlen(const char *key) { + return strlen(key); +} +#endif + size_t hash(const char *key) { - return hash_murmur((const void *)key, strlen(key)); + return hash_murmur((const void *)key, hash_strlen(key)); } -#endif /*! HAS_ASAN_DISABLE */