Skip to content

Commit

Permalink
Mark dependentSchemas as an in-place applicator (#1404)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti authored Dec 24, 2024
1 parent 4d29401 commit 8e60c8b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/jsonschema/default_walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker(
WALK(HTTPS_BASE "2020-12/vocab/applicator", "propertyNames",
ApplicatorValueInPlace)
WALK(HTTPS_BASE "2020-12/vocab/applicator", "dependentSchemas",
ApplicatorMembers)
ApplicatorMembersInPlace)
WALK_MAYBE_DEPENDENT(
HTTPS_BASE "2020-12/vocab/applicator", "contains", ApplicatorValueInPlace,
HTTPS_BASE "2020-12/vocab/validation", "minContains", "maxContains")
Expand Down Expand Up @@ -141,7 +141,7 @@ auto sourcemeta::jsontoolkit::default_schema_walker(
WALK(HTTPS_BASE "2019-09/vocab/applicator", "propertyNames",
ApplicatorValueInPlace)
WALK(HTTPS_BASE "2019-09/vocab/applicator", "dependentSchemas",
ApplicatorMembers)
ApplicatorMembersInPlace)
WALK(HTTPS_BASE "2019-09/vocab/applicator", "unevaluatedProperties",
ApplicatorValue, "properties", "patternProperties",
"additionalProperties")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ enum class SchemaWalkerStrategy : std::uint8_t {
/// takes an object as argument, whose values are potentially
/// JSON Schema definitions
ApplicatorMembers,
/// The JSON Schema keyword is an applicator that potentially
/// takes an object as argument, whose values are potentially
/// JSON Schema definitions without affecting the instance location
ApplicatorMembersInPlace,
/// The JSON Schema keyword is an applicator that may take a JSON Schema
/// definition or an array of potentially JSON Schema definitions
/// as an argument
Expand Down
3 changes: 3 additions & 0 deletions src/jsonschema/walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ auto walk(sourcemeta::jsontoolkit::Pointer &pointer,
break;
case sourcemeta::jsontoolkit::SchemaWalkerStrategy::ApplicatorMembers:
[[fallthrough]];
case sourcemeta::jsontoolkit::SchemaWalkerStrategy::
ApplicatorMembersInPlace:
[[fallthrough]];
case sourcemeta::jsontoolkit::SchemaWalkerStrategy::LocationMembers:
if (pair.second.is_object()) {
for (auto &subpair : pair.second.as_object()) {
Expand Down
2 changes: 1 addition & 1 deletion test/jsonschema/jsonschema_default_walker_2019_09_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ TEST(JSONSchema_default_walker_2019_09, applicator_dependentSchemas) {
using namespace sourcemeta::jsontoolkit;
const auto result{default_schema_walker("dependentSchemas",
VOCABULARIES_2019_09_APPLICATOR)};
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorMembers);
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorMembersInPlace);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_EQ(result.vocabulary.value(),
"https://json-schema.org/draft/2019-09/vocab/applicator");
Expand Down
2 changes: 1 addition & 1 deletion test/jsonschema/jsonschema_default_walker_2020_12_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ TEST(JSONSchema_default_walker_2020_12, applicator_dependentSchemas) {
using namespace sourcemeta::jsontoolkit;
const auto result{default_schema_walker("dependentSchemas",
VOCABULARIES_2020_12_APPLICATOR)};
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorMembers);
EXPECT_EQ(result.strategy, SchemaWalkerStrategy::ApplicatorMembersInPlace);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_EQ(result.vocabulary.value(),
"https://json-schema.org/draft/2020-12/vocab/applicator");
Expand Down

4 comments on commit 8e60c8b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/llvm)

Benchmark suite Current: 8e60c8b Previous: 4d29401 Ratio
JSON_Array_Of_Objects_Unique 334.0048747933947 ns/iter 330.0238209715093 ns/iter 1.01
JSON_Parse_1 22206.94703115784 ns/iter 21339.96286802984 ns/iter 1.04
JSON_Fast_Hash_Helm_Chart_Lock 47.819559542197496 ns/iter 47.797423281808065 ns/iter 1.00
JSON_Equality_Helm_Chart_Lock 136.94736642429524 ns/iter 137.26333027490438 ns/iter 1.00
Regex_Lower_S_Or_Upper_S_Asterisk 1.568049416429879 ns/iter 1.5691408434372698 ns/iter 1.00
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 1.5692212701077837 ns/iter 1.5675117643505716 ns/iter 1.00
Regex_Period_Asterisk 1.5674280750745855 ns/iter 1.5813048969341357 ns/iter 0.99
Regex_Group_Period_Asterisk_Group 1.5716681387755036 ns/iter 1.566703560197787 ns/iter 1.00
Regex_Period_Plus 1.8793554252464455 ns/iter 1.8795559224364577 ns/iter 1.00
Regex_Period 1.8907756693286428 ns/iter 1.9412388842513122 ns/iter 0.97
Regex_Caret_Period_Plus_Dollar 1.9003737613029605 ns/iter 1.9146641355489837 ns/iter 0.99
Regex_Caret_Group_Period_Plus_Group_Dollar 1.9659062842196229 ns/iter 1.8812862565946888 ns/iter 1.04
Regex_Caret_Period_Asterisk_Dollar 1.6238425362955005 ns/iter 1.5686100138897812 ns/iter 1.04
Regex_Caret_Group_Period_Asterisk_Group_Dollar 1.5922933888968365 ns/iter 1.582025201693213 ns/iter 1.01
Regex_Caret_X_Hyphen 6.26467843501741 ns/iter 6.265109113345188 ns/iter 1.00
Regex_Period_Md_Dollar 67.62446608424563 ns/iter 67.51602028136372 ns/iter 1.00
Regex_Caret_Slash_Period_Asterisk 4.799376616978944 ns/iter 7.117061669998747 ns/iter 0.67
Regex_Caret_Period_Range_Dollar 2.037534097426627 ns/iter 2.037985899843788 ns/iter 1.00
Regex_Nested_Backtrack 735.9499187290339 ns/iter 736.5318857981118 ns/iter 1.00
Pointer_Object_Traverse 14.762765926492822 ns/iter 14.716787985688104 ns/iter 1.00
Pointer_Object_Try_Traverse 31.501141610237376 ns/iter 31.485008319564965 ns/iter 1.00
Pointer_Push_Back_Pointer_To_Weak_Pointer 175.16131278016772 ns/iter 172.20372183574688 ns/iter 1.02

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/llvm)

Benchmark suite Current: 8e60c8b Previous: 4d29401 Ratio
JSON_Array_Of_Objects_Unique 443.8846128520479 ns/iter 440.81343934465326 ns/iter 1.01
JSON_Parse_1 30295.28470506587 ns/iter 30142.571280812506 ns/iter 1.01
JSON_Fast_Hash_Helm_Chart_Lock 54.68085755284186 ns/iter 54.725917064305186 ns/iter 1.00
JSON_Equality_Helm_Chart_Lock 149.63030954204575 ns/iter 153.40909412066452 ns/iter 0.98
Regex_Lower_S_Or_Upper_S_Asterisk 2.2066009791852026 ns/iter 2.2216591402752557 ns/iter 0.99
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 2.266619971558102 ns/iter 2.2046054200144436 ns/iter 1.03
Regex_Period_Asterisk 2.194919390109267 ns/iter 2.206098525616522 ns/iter 0.99
Regex_Group_Period_Asterisk_Group 2.188462305288205 ns/iter 2.1845016616727997 ns/iter 1.00
Regex_Period_Plus 2.4873091913683893 ns/iter 2.495225477046496 ns/iter 1.00
Regex_Period 2.4873691621272056 ns/iter 2.488492650763499 ns/iter 1.00
Regex_Caret_Period_Plus_Dollar 2.487682639471656 ns/iter 2.48770460408652 ns/iter 1.00
Regex_Caret_Group_Period_Plus_Group_Dollar 2.3111831246096197 ns/iter 2.4864442875559583 ns/iter 0.93
Regex_Caret_Period_Asterisk_Dollar 2.4876186414232246 ns/iter 3.420649576183184 ns/iter 0.73
Regex_Caret_Group_Period_Asterisk_Group_Dollar 2.4862727781865455 ns/iter 3.418699197732234 ns/iter 0.73
Regex_Caret_X_Hyphen 13.050043371299582 ns/iter 12.542905328985935 ns/iter 1.04
Regex_Period_Md_Dollar 74.63292893310485 ns/iter 73.64919584171531 ns/iter 1.01
Regex_Caret_Slash_Period_Asterisk 6.2199471767005745 ns/iter 7.147100822326368 ns/iter 0.87
Regex_Caret_Period_Range_Dollar 3.72616498657472 ns/iter 3.730256029295508 ns/iter 1.00
Regex_Nested_Backtrack 492.6023592562248 ns/iter 506.6397810073343 ns/iter 0.97
Pointer_Object_Traverse 45.043978090562995 ns/iter 46.22827127779616 ns/iter 0.97
Pointer_Object_Try_Traverse 52.25831875253182 ns/iter 52.60098910749095 ns/iter 0.99
Pointer_Push_Back_Pointer_To_Weak_Pointer 351.89407746365566 ns/iter 352.0334902126427 ns/iter 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (windows/msvc)

Benchmark suite Current: 8e60c8b Previous: 4d29401 Ratio
JSON_Array_Of_Objects_Unique 415.0628207560955 ns/iter 420.9886461367191 ns/iter 0.99
JSON_Parse_1 79644.70982143114 ns/iter 83011.65178572488 ns/iter 0.96
JSON_Fast_Hash_Helm_Chart_Lock 53.94658000000163 ns/iter 50.84380999999212 ns/iter 1.06
JSON_Equality_Helm_Chart_Lock 219.63156608789353 ns/iter 221.21043750004787 ns/iter 0.99
Regex_Lower_S_Or_Upper_S_Asterisk 8.355697730556907 ns/iter 8.087111607143324 ns/iter 1.03
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 8.090141741072491 ns/iter 8.227173177558669 ns/iter 0.98
Regex_Period_Asterisk 8.30289174107181 ns/iter 7.806926750860373 ns/iter 1.06
Regex_Group_Period_Asterisk_Group 7.876170758928578 ns/iter 8.055634785465866 ns/iter 0.98
Regex_Period_Plus 8.044601749800371 ns/iter 8.199824963394052 ns/iter 0.98
Regex_Period 8.06613504464236 ns/iter 7.78716964285664 ns/iter 1.04
Regex_Caret_Period_Plus_Dollar 8.118054874475044 ns/iter 7.850684151787642 ns/iter 1.03
Regex_Caret_Group_Period_Plus_Group_Dollar 8.106586570953164 ns/iter 8.12962362442251 ns/iter 1.00
Regex_Caret_Period_Asterisk_Dollar 7.819620500806067 ns/iter 8.431324515930825 ns/iter 0.93
Regex_Caret_Group_Period_Asterisk_Group_Dollar 7.836523437500124 ns/iter 7.960749999999755 ns/iter 0.98
Regex_Caret_X_Hyphen 11.637526785713298 ns/iter 11.902943750001782 ns/iter 0.98
Regex_Period_Md_Dollar 141.28333967483545 ns/iter 142.76191103741175 ns/iter 0.99
Regex_Caret_Slash_Period_Asterisk 11.702973214283928 ns/iter 11.593600000001711 ns/iter 1.01
Regex_Caret_Period_Range_Dollar 9.18114999999986 ns/iter 8.701201300440443 ns/iter 1.06
Regex_Nested_Backtrack 588.5866964287549 ns/iter 585.5511607143578 ns/iter 1.01
Pointer_Object_Traverse 55.909285714282724 ns/iter 55.78818749999722 ns/iter 1.00
Pointer_Object_Try_Traverse 75.5830915178533 ns/iter 76.06305803571038 ns/iter 0.99
Pointer_Push_Back_Pointer_To_Weak_Pointer 175.00090234380963 ns/iter 182.53295379753393 ns/iter 0.96

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/gcc)

Benchmark suite Current: 8e60c8b Previous: 4d29401 Ratio
Pointer_Object_Traverse 46.09613872671311 ns/iter 45.12204188821551 ns/iter 1.02
Pointer_Object_Try_Traverse 22.46732424517253 ns/iter 22.499430231748985 ns/iter 1.00
Pointer_Push_Back_Pointer_To_Weak_Pointer 213.29006133055077 ns/iter 214.234425252768 ns/iter 1.00
Regex_Lower_S_Or_Upper_S_Asterisk 2.487498845090884 ns/iter 2.488401736908652 ns/iter 1.00
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar 2.4892672682644856 ns/iter 2.4862393924871404 ns/iter 1.00
Regex_Period_Asterisk 2.4882338179537236 ns/iter 2.487900363789102 ns/iter 1.00
Regex_Group_Period_Asterisk_Group 2.488417506436234 ns/iter 2.4871928419047524 ns/iter 1.00
Regex_Period_Plus 2.797667702316193 ns/iter 2.796922953945781 ns/iter 1.00
Regex_Period 2.803504455317331 ns/iter 2.7966113423191254 ns/iter 1.00
Regex_Caret_Period_Plus_Dollar 2.7979738060905768 ns/iter 2.7974580496273185 ns/iter 1.00
Regex_Caret_Group_Period_Plus_Group_Dollar 2.8003464396171514 ns/iter 2.797312638223487 ns/iter 1.00
Regex_Caret_Period_Asterisk_Dollar 3.732406658428591 ns/iter 3.729709167525733 ns/iter 1.00
Regex_Caret_Group_Period_Asterisk_Group_Dollar 3.729700543472691 ns/iter 3.734362388273515 ns/iter 1.00
Regex_Caret_X_Hyphen 13.055414866615436 ns/iter 12.430786360953292 ns/iter 1.05
Regex_Period_Md_Dollar 88.27876647295834 ns/iter 88.21321264574435 ns/iter 1.00
Regex_Caret_Slash_Period_Asterisk 7.151539374636085 ns/iter 6.2175190870194745 ns/iter 1.15
Regex_Caret_Period_Range_Dollar 4.042425983761726 ns/iter 4.043999113816224 ns/iter 1.00
Regex_Nested_Backtrack 813.5116573484303 ns/iter 813.3757256812958 ns/iter 1.00
JSON_Array_Of_Objects_Unique 378.96437812283585 ns/iter 378.20218608427933 ns/iter 1.00
JSON_Parse_1 32963.44451706177 ns/iter 32485.695694669725 ns/iter 1.01
JSON_Fast_Hash_Helm_Chart_Lock 62.825596554458485 ns/iter 62.54410462209097 ns/iter 1.00
JSON_Equality_Helm_Chart_Lock 143.1913140227064 ns/iter 143.13795216405296 ns/iter 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.