diff --git a/kernel/drivertools.h b/kernel/drivertools.h index 19c9c2e34..e584f4d39 100644 --- a/kernel/drivertools.h +++ b/kernel/drivertools.h @@ -1067,10 +1067,11 @@ public: DriveSpec &operator=(DriveBitMultiple const &bit) { return *this = DriveBit(bit); } void updhash() const { - DriveSpec *that = (DriveSpec*)this; + if (hash_ != 0) + return; pack(); - that->hash_ = run_hash(chunks_); - that->hash_ |= (that->hash_ == 0); + hash_ = run_hash(chunks_); + hash_ |= (hash_ == 0); } Hasher hash_into(Hasher h) const; @@ -1372,9 +1373,7 @@ inline Hasher DriveChunk::hash_into(Hasher h) const inline Hasher DriveSpec::hash_into(Hasher h) const { - if (hash_ == 0) - updhash(); - + updhash(); h.eat(hash_); return h; } diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 5b1a2a877..0e712a2a3 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -116,7 +116,7 @@ private: return; } void hash64(uint64_t i) { - state = djb2_xor((uint32_t)(i % (1ULL << 32ULL)), state); + state = djb2_xor((uint32_t)(i & 0xFFFFFFFFULL), state); state = djb2_xor((uint32_t)(i >> 32ULL), state); state = mkhash_xorshift(fudge ^ state); return; @@ -163,10 +163,7 @@ struct hash_ops { return a == b; } static inline Hasher hash_into(const T &a, Hasher h) { - if constexpr (std::is_same_v) { - h.hash32(a ? 1 : 0); - return h; - } else if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v) { static_assert(sizeof(T) <= sizeof(uint64_t)); if (sizeof(T) == sizeof(uint64_t)) h.hash64(a); @@ -221,7 +218,7 @@ template struct hash_ops> { return a == b; } static inline Hasher hash_into(std::vector a, Hasher h) { - h.eat(a.size()); + h.eat((uint32_t)a.size()); for (auto k : a) h.eat(k); return h; @@ -241,10 +238,7 @@ template struct hash_ops> { struct hash_cstr_ops { static inline bool cmp(const char *a, const char *b) { - for (int i = 0; a[i] || b[i]; i++) - if (a[i] != b[i]) - return false; - return true; + return strcmp(a, b) == 0; } static inline Hasher hash_into(const char *a, Hasher h) { while (*a)