Skip to content

Commit 5b226d2

Browse files
authored
Improve SchemaFrame to use more weak pointers (#2182)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent f696b2c commit 5b226d2

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/core/jsonschema/frame.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -979,9 +979,9 @@ auto SchemaFrame::references() const noexcept -> const References & {
979979
}
980980

981981
auto SchemaFrame::reference(const SchemaReferenceType type,
982-
const Pointer &pointer) const
982+
const WeakPointer &pointer) const
983983
-> std::optional<std::reference_wrapper<const ReferencesEntry>> {
984-
const auto result{this->references_.find({type, pointer})};
984+
const auto result{this->references_.find({type, to_pointer(pointer)})};
985985
if (result != this->references_.cend()) {
986986
return result->second;
987987
}
@@ -1015,16 +1015,16 @@ auto SchemaFrame::vocabularies(const Location &location,
10151015
}
10161016

10171017
auto SchemaFrame::uri(const Location &location,
1018-
const Pointer &relative_schema_location) const
1018+
const WeakPointer &relative_schema_location) const
10191019
-> JSON::String {
1020-
return to_uri(to_pointer(this->relative_instance_location(location))
1021-
.concat(relative_schema_location),
1020+
return to_uri(this->relative_instance_location(location).concat(
1021+
relative_schema_location),
10221022
location.base)
10231023
.recompose();
10241024
}
10251025

10261026
auto SchemaFrame::traverse(const Location &location,
1027-
const Pointer &relative_schema_location) const
1027+
const WeakPointer &relative_schema_location) const
10281028
-> const Location & {
10291029
const auto new_uri{this->uri(location, relative_schema_location)};
10301030
const auto static_match{
@@ -1082,11 +1082,11 @@ auto SchemaFrame::uri(const WeakPointer &pointer) const
10821082
}
10831083

10841084
auto SchemaFrame::dereference(const Location &location,
1085-
const Pointer &relative_schema_location) const
1085+
const WeakPointer &relative_schema_location) const
10861086
-> std::pair<SchemaReferenceType,
10871087
std::optional<std::reference_wrapper<const Location>>> {
10881088
const auto effective_location{
1089-
to_pointer(location.pointer).concat(relative_schema_location)};
1089+
to_pointer(location.pointer.concat(relative_schema_location))};
10901090
const auto maybe_reference_entry{this->references_.find(
10911091
{SchemaReferenceType::Static, effective_location})};
10921092
if (maybe_reference_entry == this->references_.cend()) {

src/core/jsonschema/include/sourcemeta/core/jsonschema_frame.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
153153

154154
/// Get a specific reference entry by type and pointer
155155
[[nodiscard]] auto reference(const SchemaReferenceType type,
156-
const Pointer &pointer) const
156+
const WeakPointer &pointer) const
157157
-> std::optional<std::reference_wrapper<const ReferencesEntry>>;
158158

159159
/// Check whether the analysed schema has no external references
@@ -170,12 +170,12 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
170170
/// Get the URI associated with a location entry
171171
[[nodiscard]] auto
172172
uri(const Location &location,
173-
const Pointer &relative_schema_location = empty_pointer) const
173+
const WeakPointer &relative_schema_location = empty_weak_pointer) const
174174
-> JSON::String;
175175

176176
/// Get the location associated by traversing a pointer from another location
177177
[[nodiscard]] auto traverse(const Location &location,
178-
const Pointer &relative_schema_location) const
178+
const WeakPointer &relative_schema_location) const
179179
-> const Location &;
180180

181181
/// Get the location associated with a given URI
@@ -191,9 +191,9 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
191191
-> std::optional<std::reference_wrapper<const JSON::String>>;
192192

193193
/// Try to dereference a reference location into its destination location
194-
[[nodiscard]] auto
195-
dereference(const Location &location,
196-
const Pointer &relative_schema_location = empty_pointer) const
194+
[[nodiscard]] auto dereference(
195+
const Location &location,
196+
const WeakPointer &relative_schema_location = empty_weak_pointer) const
197197
-> std::pair<SchemaReferenceType,
198198
std::optional<std::reference_wrapper<const Location>>>;
199199

src/extension/alterschema/common/unknown_local_ref.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class UnknownLocalRef final : public SchemaTransformRule {
2929
schema.at(KEYWORD).is_string());
3030

3131
// Find the keyword location entry
32-
const auto keyword_pointer{to_pointer(location.pointer).concat({KEYWORD})};
32+
auto keyword_pointer{location.pointer};
33+
keyword_pointer.push_back(std::cref(KEYWORD));
3334
const auto reference_entry{
3435
frame.reference(SchemaReferenceType::Static, keyword_pointer)};
3536
ONLY_CONTINUE_IF(reference_entry.has_value());

0 commit comments

Comments
 (0)