From 29d42a3910abe6051992820f9c3fa08c7b49217f Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Fri, 25 Nov 2022 17:24:35 -0500 Subject: Faster hashing of rapidjson values --- rapidjsonwrapper.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/rapidjsonwrapper.h b/rapidjsonwrapper.h index dfc1fde9..e12465d6 100644 --- a/rapidjsonwrapper.h +++ b/rapidjsonwrapper.h @@ -106,29 +106,27 @@ static inline uint64_t HashRapidValue(const rapidjson::Value& val) } case rapidjson::kNumberType: { - size_t h; - if (val.IsDouble()) + if (val.IsInt64()) { - const double dVal = val.GetDouble(); - h = HashBytes(&dVal, sizeof(dVal)); + return combine(type, static_cast(val.GetInt64())); } - else if (val.IsInt()) + else if (val.IsUint64()) { - h = static_cast(val.GetInt()); + return combine(type, val.GetUint64()); } - else if (val.IsInt64()) + else if (val.IsUint()) { - h = static_cast(val.GetUint64()); + return combine(type, static_cast(val.GetUint())); } - else if (val.IsUint()) + else if (val.IsInt()) { - h = static_cast(val.GetUint()); + return combine(type, static_cast(val.GetInt())); } else { - h = val.GetUint64(); + const double dVal = val.GetDouble(); + return combine(type, HashBytes(&dVal, sizeof(dVal))); } - return combine(type, h); } default: -- cgit v1.3.1