diff --git a/DEPENDENCIES b/DEPENDENCIES index ecb9c8670..f406995c6 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,5 +1,5 @@ vendorpull https://github.com/sourcemeta/vendorpull 70342aaf458e6cb80baeb5b718901075fc42ede6 -noa https://github.com/sourcemeta/noa dee6c859895baf918fe3ecca22e4e7a262c5d500 +noa https://github.com/sourcemeta/noa ee488bdc06f5587dc132012b6aabcdaea98c973e jsontestsuite https://github.com/nst/JSONTestSuite d64aefb55228d9584d3e5b2433f720ea8fd00c82 jsonschema-2020-12 https://github.com/json-schema-org/json-schema-spec 769daad75a9553562333a8937a187741cb708c72 jsonschema-2019-09 https://github.com/json-schema-org/json-schema-spec 41014ea723120ce70b314d72f863c6929d9f3cfd diff --git a/src/json/json_value.cc b/src/json/json_value.cc index dbe3fa206..119112c15 100644 --- a/src/json/json_value.cc +++ b/src/json/json_value.cc @@ -668,8 +668,7 @@ JSON::at(const String &key, [[nodiscard]] auto JSON::try_at(const JSON::String &key) const -> const JSON * { assert(this->is_object()); const auto &object{this->data_object}; - const auto value{object.data.find(key, object.data.hash(key))}; - return value == object.data.cend() ? nullptr : &value->second; + return object.data.try_at(key, object.data.hash(key)); } [[nodiscard]] auto @@ -678,8 +677,7 @@ JSON::try_at(const String &key, -> const JSON * { assert(this->is_object()); const auto &object{this->data_object}; - const auto value{object.data.find(key, hash)}; - return value == object.data.cend() ? nullptr : &value->second; + return object.data.try_at(key, hash); } [[nodiscard]] auto JSON::defines(const JSON::String &key) const -> bool { diff --git a/vendor/noa/src/flat_map/include/sourcemeta/noa/flat_map.h b/vendor/noa/src/flat_map/include/sourcemeta/noa/flat_map.h index e253326cc..9c38da84f 100644 --- a/vendor/noa/src/flat_map/include/sourcemeta/noa/flat_map.h +++ b/vendor/noa/src/flat_map/include/sourcemeta/noa/flat_map.h @@ -129,6 +129,29 @@ template class FlatMap { return this->cend(); } + inline auto try_at(const key_type &key, const hash_type key_hash) const + -> const mapped_type * { + assert(this->hash(key) == key_hash); + + // Move the perfect hash condition out of the loop for extra performance + if (this->hasher.is_perfect(key_hash)) { + for (size_type index = 0; index < this->data.size(); index++) { + if (this->data[index].hash == key_hash) { + return &this->data[index].second; + } + } + } else { + for (size_type index = 0; index < this->data.size(); index++) { + if (this->data[index].hash == key_hash && + this->data[index].first == key) { + return &this->data[index].second; + } + } + } + + return nullptr; + } + // As a performance optimisation if the hash is known auto contains(const key_type &key, const hash_type key_hash) const -> bool { assert(this->hash(key) == key_hash);