diff --git a/src/core/json/construct.h b/src/core/json/construct.h index c2cd5674d..f7c5661bf 100644 --- a/src/core/json/construct.h +++ b/src/core/json/construct.h @@ -500,10 +500,10 @@ do_construct_object_key: { const auto key_length{key_entry.length}; if (std::memchr(key_data, '\\', key_length)) { key = internal::unescape_string(key_data, key_length); - key_hash = frames.back().get().as_object().hash(key); + key_hash = Result::Object::hash(key); } else { key.assign(key_data, key_length); - key_hash = frames.back().get().as_object().hash(key_data, key_length); + key_hash = Result::Object::hash(key_data, key_length); } key_line = key_entry.line; key_column = key_entry.column; diff --git a/src/core/json/include/sourcemeta/core/json_object.h b/src/core/json/include/sourcemeta/core/json_object.h index b0e5585a1..6b2abb5dc 100644 --- a/src/core/json/include/sourcemeta/core/json_object.h +++ b/src/core/json/include/sourcemeta/core/json_object.h @@ -132,20 +132,20 @@ template class JSONObject { // the `Key`-accepting overload as before. /// Compute a hash for a key - [[nodiscard]] inline auto hash(const Key &key) const noexcept -> hash_type { - return this->hasher(key); + [[nodiscard]] static inline auto hash(const Key &key) noexcept -> hash_type { + return hasher(key); } /// Compute a hash for a key template requires std::same_as, KeyView> - [[nodiscard]] inline auto hash(T key) const noexcept -> hash_type { - return this->hasher(key.data(), key.size()); + [[nodiscard]] static inline auto hash(T key) noexcept -> hash_type { + return hasher(key.data(), key.size()); } /// Compute a hash from raw data - [[nodiscard]] inline auto hash(const char *raw_data, - const std::size_t raw_size) const noexcept + [[nodiscard]] static inline auto hash(const char *raw_data, + const std::size_t raw_size) noexcept -> hash_type { return hasher(raw_data, raw_size); } diff --git a/src/core/jsonrpc/jsonrpc.cc b/src/core/jsonrpc/jsonrpc.cc index 8aa10ade4..1217dec8d 100644 --- a/src/core/jsonrpc/jsonrpc.cc +++ b/src/core/jsonrpc/jsonrpc.cc @@ -10,24 +10,17 @@ namespace { -const auto JSONRPC_HASH_ID{ - sourcemeta::core::JSON::make_object().as_object().hash("id")}; +const auto JSONRPC_HASH_ID{sourcemeta::core::JSON::Object::hash("id")}; const auto JSONRPC_HASH_JSONRPC{ - sourcemeta::core::JSON::make_object().as_object().hash("jsonrpc")}; -const auto JSONRPC_HASH_METHOD{ - sourcemeta::core::JSON::make_object().as_object().hash("method")}; -const auto JSONRPC_HASH_RESULT{ - sourcemeta::core::JSON::make_object().as_object().hash("result")}; -const auto JSONRPC_HASH_ERROR{ - sourcemeta::core::JSON::make_object().as_object().hash("error")}; -const auto JSONRPC_HASH_CODE{ - sourcemeta::core::JSON::make_object().as_object().hash("code")}; + sourcemeta::core::JSON::Object::hash("jsonrpc")}; +const auto JSONRPC_HASH_METHOD{sourcemeta::core::JSON::Object::hash("method")}; +const auto JSONRPC_HASH_RESULT{sourcemeta::core::JSON::Object::hash("result")}; +const auto JSONRPC_HASH_ERROR{sourcemeta::core::JSON::Object::hash("error")}; +const auto JSONRPC_HASH_CODE{sourcemeta::core::JSON::Object::hash("code")}; const auto JSONRPC_HASH_MESSAGE{ - sourcemeta::core::JSON::make_object().as_object().hash("message")}; -const auto JSONRPC_HASH_DATA{ - sourcemeta::core::JSON::make_object().as_object().hash("data")}; -const auto JSONRPC_HASH_PARAMS{ - sourcemeta::core::JSON::make_object().as_object().hash("params")}; + sourcemeta::core::JSON::Object::hash("message")}; +const auto JSONRPC_HASH_DATA{sourcemeta::core::JSON::Object::hash("data")}; +const auto JSONRPC_HASH_PARAMS{sourcemeta::core::JSON::Object::hash("params")}; } // namespace diff --git a/test/json/json_auto_test.cc b/test/json/json_auto_test.cc index befd5a1c4..fc82835bc 100644 --- a/test/json/json_auto_test.cc +++ b/test/json/json_auto_test.cc @@ -42,8 +42,7 @@ TEST(JSON_auto, class_with_custom_method) { } TEST(JSON_auto, object_hash) { - const auto value{ - sourcemeta::core::JSON::make_object().as_object().hash("foo")}; + const auto value{sourcemeta::core::JSON::Object::hash("foo")}; const auto result{sourcemeta::core::to_json(value)}; EXPECT_TRUE(result.is_array()); EXPECT_FALSE(result.empty());