--- deliantra/server/include/util.h 2008/12/30 07:24:16 1.83 +++ deliantra/server/include/util.h 2008/12/31 17:35:37 1.84 @@ -43,8 +43,8 @@ // put into ifs if you are very sure that the expression // is mostly true or mosty false. note that these return // booleans, not the expression. -#define expect_false(expr) expect ((expr) != 0, 0) -#define expect_true(expr) expect ((expr) != 0, 1) +#define expect_false(expr) expect ((expr) ? 1 : 0, 0) +#define expect_true(expr) expect ((expr) ? 1 : 0, 1) #include @@ -542,7 +542,8 @@ { std::size_t operator ()(const char *s) const { - unsigned long hash = 0; +#if 0 + uint32_t hash = 0; /* use the one-at-a-time hash function, which supposedly is * better than the djb2-like one used by perl5.005, but @@ -559,6 +560,17 @@ hash += hash << 3; hash ^= hash >> 11; hash += hash << 15; +#else + // use FNV-1a hash (http://isthe.com/chongo/tech/comp/fnv/) + // it is about twice as fast as the one-at-a-time one, + // with good distribution. + // FNV-1a is faster on many cpus because the multiplication + // runs concurrent with the looping logic. + uint32_t hash = 2166136261; + + while (*s) + hash = (hash ^ *s++) * 16777619; +#endif return hash; }