Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/json/construct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/core/json/include/sourcemeta/core/json_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ template <typename Key, typename Value, typename Hash> 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 <typename T>
requires std::same_as<std::remove_cvref_t<T>, 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);
}
Expand Down
25 changes: 9 additions & 16 deletions src/core/jsonrpc/jsonrpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions test/json/json_auto_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading