mirror of
https://github.com/nlohmann/json.git
synced 2026-10-18 12:08:12 +00:00
Mask the JSON pointer hash constants without a cast to uint64_t
The cast is useless where size_t is uint64_t (GCC -Wuseless-cast); the mask alone already keeps the constants in size_t's range. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+4
-6
No files matched your search
@@ -12,7 +12,6 @@
|
|||||||
#include <cctype> // isdigit
|
#include <cctype> // isdigit
|
||||||
#include <cerrno> // errno, ERANGE
|
#include <cerrno> // errno, ERANGE
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint64_t
|
|
||||||
#include <cstdlib> // strtoull
|
#include <cstdlib> // strtoull
|
||||||
#ifndef JSON_NO_IO
|
#ifndef JSON_NO_IO
|
||||||
#include <iosfwd> // ostream
|
#include <iosfwd> // ostream
|
||||||
@@ -531,10 +530,10 @@ class json_pointer
|
|||||||
|
|
||||||
static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept
|
static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept
|
||||||
{
|
{
|
||||||
std::size_t h = parent * static_cast<std::size_t>(0x9E3779B97F4A7C15ULL & static_cast<std::uint64_t>((std::numeric_limits<std::size_t>::max)()));
|
std::size_t h = parent * static_cast<std::size_t>(0x9E3779B97F4A7C15ULL & (std::numeric_limits<std::size_t>::max)());
|
||||||
for (std::size_t i = 0; i < token.size(); ++i)
|
for (std::size_t i = 0; i < token.size(); ++i)
|
||||||
{
|
{
|
||||||
h = (h ^ static_cast<unsigned char>(token[i])) * static_cast<std::size_t>(0x100000001B3ULL & static_cast<std::uint64_t>((std::numeric_limits<std::size_t>::max)()));
|
h = (h ^ static_cast<unsigned char>(token[i])) * static_cast<std::size_t>(0x100000001B3ULL & (std::numeric_limits<std::size_t>::max)());
|
||||||
}
|
}
|
||||||
return h ^ (h >> 29u);
|
return h ^ (h >> 29u);
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+2
-3
@@ -20978,7 +20978,6 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
#include <cctype> // isdigit
|
#include <cctype> // isdigit
|
||||||
#include <cerrno> // errno, ERANGE
|
#include <cerrno> // errno, ERANGE
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint64_t
|
|
||||||
#include <cstdlib> // strtoull
|
#include <cstdlib> // strtoull
|
||||||
#ifndef JSON_NO_IO
|
#ifndef JSON_NO_IO
|
||||||
#include <iosfwd> // ostream
|
#include <iosfwd> // ostream
|
||||||
@@ -21504,10 +21503,10 @@ class json_pointer
|
|||||||
|
|
||||||
static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept
|
static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept
|
||||||
{
|
{
|
||||||
std::size_t h = parent * static_cast<std::size_t>(0x9E3779B97F4A7C15ULL & static_cast<std::uint64_t>((std::numeric_limits<std::size_t>::max)()));
|
std::size_t h = parent * static_cast<std::size_t>(0x9E3779B97F4A7C15ULL & (std::numeric_limits<std::size_t>::max)());
|
||||||
for (std::size_t i = 0; i < token.size(); ++i)
|
for (std::size_t i = 0; i < token.size(); ++i)
|
||||||
{
|
{
|
||||||
h = (h ^ static_cast<unsigned char>(token[i])) * static_cast<std::size_t>(0x100000001B3ULL & static_cast<std::uint64_t>((std::numeric_limits<std::size_t>::max)()));
|
h = (h ^ static_cast<unsigned char>(token[i])) * static_cast<std::size_t>(0x100000001B3ULL & (std::numeric_limits<std::size_t>::max)());
|
||||||
}
|
}
|
||||||
return h ^ (h >> 29u);
|
return h ^ (h >> 29u);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user