Skip to content

Commit

Permalink
refactor(walker): use std::ranges:sort instead of std::sort (#1267)
Browse files Browse the repository at this point in the history
Clang tidy recommandation

Signed-off-by: Tony Gorez <[email protected]>
  • Loading branch information
tony-go authored Oct 4, 2024
1 parent 82e48f0 commit 5ceffcc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/jsonschema/walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#include <sourcemeta/jsontoolkit/jsonschema.h>
#include <sourcemeta/jsontoolkit/jsonschema_walker.h>

#include <algorithm> // std::max, std::sort
#include <algorithm> // std::max
#include <cassert> // assert
#include <numeric> // std::accumulate
#include <ranges> // std::ranges::sort

auto sourcemeta::jsontoolkit::keyword_priority(
std::string_view keyword, const std::map<std::string, bool> &vocabularies,
Expand Down Expand Up @@ -207,8 +208,8 @@ sourcemeta::jsontoolkit::SchemaKeywordIterator::SchemaKeywordIterator(
}

// Sort keywords based on priority for correct evaluation
std::sort(
this->entries.begin(), this->entries.end(),
std::ranges::sort(
this->entries,
[&vocabularies, &walker](const auto &left, const auto &right) -> bool {
// These cannot be empty or indexes, as we created
// the entries array from a JSON object
Expand Down

4 comments on commit 5ceffcc

@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: 5ceffcc Previous: 82e48f0 Ratio
JSON_Array_Of_Objects_Unique 3784.8978662231107 ns/iter 3995.5399262600627 ns/iter 0.95
JSONSchema_Validate_Draft4_Meta_1_No_Callback 798.8841480558408 ns/iter 774.0963649633727 ns/iter 1.03
JSONSchema_Validate_Draft4_Required_Properties 1015.6660752904231 ns/iter 973.9796454891994 ns/iter 1.04
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 161.79997970870286 ns/iter 160.44223548699966 ns/iter 1.01
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 112.3691521948755 ns/iter 106.55257426723915 ns/iter 1.05
JSONSchema_Validate_Draft4_Items_Schema 2818.090088091676 ns/iter 2768.946745052337 ns/iter 1.02
JSONSchema_Validate_Draft4_Nested_Object 1441.3055751119657 ns/iter 1401.4626568295323 ns/iter 1.03
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1500.132463669815 ns/iter 1393.7266897106397 ns/iter 1.08
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1121.4930756209956 ns/iter 1058.959850077662 ns/iter 1.06
JSONSchema_Validate_Draft4_Properties_Triad_Required 1485.3545476358092 ns/iter 1417.2136118878116 ns/iter 1.05
JSONSchema_Validate_Draft4_Non_Recursive_Ref 208.26287991411326 ns/iter 199.13361110570705 ns/iter 1.05
JSONSchema_Validate_Draft4_Pattern_Properties_True 1463.0809322059686 ns/iter 1390.9907556116348 ns/iter 1.05
JSONSchema_Validate_Draft4_Ref_To_Single_Property 115.67794671711938 ns/iter 108.34658072614582 ns/iter 1.07
JSONSchema_Validate_Draft4_Additional_Properties_Type 378.59047267176106 ns/iter 363.2046208696293 ns/iter 1.04
JSONSchema_Validate_Draft4_Nested_Oneof 389.84884271118574 ns/iter 373.6773191551827 ns/iter 1.04
JSONSchema_Validate_Draft6_Property_Names 824.0157211933015 ns/iter 833.5054035017199 ns/iter 0.99
JSONSchema_Validate_Draft7_If_Then_Else 180.61002675001055 ns/iter 175.0987496403575 ns/iter 1.03
JSONSchema_Compiler_Draft6_AdaptiveCard 3342542166.000044 ns/iter 3090445666.0000505 ns/iter 1.08

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: 5ceffcc Previous: 82e48f0 Ratio
JSON_Array_Of_Objects_Unique 2102.8682742975384 ns/iter 2157.632373842345 ns/iter 0.97
JSONSchema_Validate_Draft4_Meta_1_No_Callback 1036.620636559516 ns/iter 1039.7991880747188 ns/iter 1.00
JSONSchema_Validate_Draft4_Required_Properties 1669.2732172160615 ns/iter 1614.5905004111223 ns/iter 1.03
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 186.8406769637506 ns/iter 185.65373306501732 ns/iter 1.01
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 133.1222628404555 ns/iter 128.3631592657806 ns/iter 1.04
JSONSchema_Validate_Draft4_Items_Schema 4289.51846217136 ns/iter 4299.987658124528 ns/iter 1.00
JSONSchema_Validate_Draft4_Nested_Object 1739.19234938634 ns/iter 1682.5719451538118 ns/iter 1.03
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1835.6381803921238 ns/iter 1713.7772765254813 ns/iter 1.07
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1532.6239369146244 ns/iter 1509.314484189926 ns/iter 1.02
JSONSchema_Validate_Draft4_Properties_Triad_Required 1920.9372444179876 ns/iter 1818.0167556205147 ns/iter 1.06
JSONSchema_Validate_Draft4_Non_Recursive_Ref 486.2986283149758 ns/iter 475.75539897047116 ns/iter 1.02
JSONSchema_Validate_Draft4_Pattern_Properties_True 2558.4363684810396 ns/iter 2515.7972994172937 ns/iter 1.02
JSONSchema_Validate_Draft4_Ref_To_Single_Property 135.7339554324512 ns/iter 127.58868399257445 ns/iter 1.06
JSONSchema_Validate_Draft4_Additional_Properties_Type 605.6757889058457 ns/iter 580.4769145279405 ns/iter 1.04
JSONSchema_Validate_Draft4_Nested_Oneof 537.5680509982101 ns/iter 515.6152899999711 ns/iter 1.04
JSONSchema_Validate_Draft6_Property_Names 1312.5223155077078 ns/iter 1240.4018184600209 ns/iter 1.06
JSONSchema_Validate_Draft7_If_Then_Else 231.22807340615944 ns/iter 215.14917095432887 ns/iter 1.07
JSONSchema_Compiler_Draft6_AdaptiveCard 5673500844.000046 ns/iter 5373003992.999997 ns/iter 1.06

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: 5ceffcc Previous: 82e48f0 Ratio
JSONSchema_Compiler_Draft6_AdaptiveCard 6410052627.000028 ns/iter 6344971050.000027 ns/iter 1.01
JSONSchema_Validate_Draft4_Meta_1_No_Callback 1059.0876412458883 ns/iter 1101.7370410671253 ns/iter 0.96
JSONSchema_Validate_Draft4_Required_Properties 2368.5063835362707 ns/iter 2452.780128552883 ns/iter 0.97
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 190.48707913190503 ns/iter 198.62687127674397 ns/iter 0.96
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 138.9728414495219 ns/iter 139.6465332796852 ns/iter 1.00
JSONSchema_Validate_Draft4_Items_Schema 3062.40769395784 ns/iter 3210.1044838342923 ns/iter 0.95
JSONSchema_Validate_Draft4_Nested_Object 1727.9609674477003 ns/iter 1738.539516699736 ns/iter 0.99
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1667.5505133436793 ns/iter 1660.937222939609 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1364.7976551895158 ns/iter 1362.435432927389 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Required 1751.708448345078 ns/iter 1748.9823828016085 ns/iter 1.00
JSONSchema_Validate_Draft4_Non_Recursive_Ref 480.813844012553 ns/iter 469.6774187476461 ns/iter 1.02
JSONSchema_Validate_Draft4_Pattern_Properties_True 2335.4275254419463 ns/iter 2274.872455433494 ns/iter 1.03
JSONSchema_Validate_Draft4_Ref_To_Single_Property 143.7310665749886 ns/iter 145.2288361287263 ns/iter 0.99
JSONSchema_Validate_Draft4_Additional_Properties_Type 1151.345635421773 ns/iter 1105.2671683420886 ns/iter 1.04
JSONSchema_Validate_Draft4_Nested_Oneof 430.5515434301001 ns/iter 450.09989079108357 ns/iter 0.96
JSONSchema_Validate_Draft6_Property_Names 1621.6906341211466 ns/iter 1659.6565147250892 ns/iter 0.98
JSONSchema_Validate_Draft7_If_Then_Else 197.02103190509737 ns/iter 198.45794650635798 ns/iter 0.99
JSON_Array_Of_Objects_Unique 3192.577458775558 ns/iter 3325.380590459243 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 (windows/msvc)

Benchmark suite Current: 5ceffcc Previous: 82e48f0 Ratio
JSON_Array_Of_Objects_Unique 5240.476999999828 ns/iter 4823.296927001978 ns/iter 1.09
JSONSchema_Validate_Draft4_Meta_1_No_Callback 2338.3346670372407 ns/iter 2334.2903635150774 ns/iter 1.00
JSONSchema_Validate_Draft4_Required_Properties 2022.3498686937967 ns/iter 2013.1662870159178 ns/iter 1.00
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 539.5201785713003 ns/iter 544.8323999999047 ns/iter 0.99
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 412.2105976690715 ns/iter 407.3492362791203 ns/iter 1.01
JSONSchema_Validate_Draft4_Items_Schema 6471.800892857767 ns/iter 6558.627678572293 ns/iter 0.99
JSONSchema_Validate_Draft4_Nested_Object 3940.3934151785843 ns/iter 3900.4547991071195 ns/iter 1.01
JSONSchema_Validate_Draft4_Properties_Triad_Optional 5405.448999999861 ns/iter 5368.767857143147 ns/iter 1.01
JSONSchema_Validate_Draft4_Properties_Triad_Closed 4449.199588305518 ns/iter 4390.579999999034 ns/iter 1.01
JSONSchema_Validate_Draft4_Properties_Triad_Required 5485.45357143025 ns/iter 5529.692857142062 ns/iter 0.99
JSONSchema_Validate_Draft4_Non_Recursive_Ref 557.5144000001728 ns/iter 560.7289285714095 ns/iter 0.99
JSONSchema_Validate_Draft4_Pattern_Properties_True 8083.485491073057 ns/iter 7962.8504464273365 ns/iter 1.02
JSONSchema_Validate_Draft4_Ref_To_Single_Property 410.81234326723455 ns/iter 411.6882897727424 ns/iter 1.00
JSONSchema_Validate_Draft4_Additional_Properties_Type 773.9575892859054 ns/iter 771.5140624997881 ns/iter 1.00
JSONSchema_Validate_Draft4_Nested_Oneof 1087.4649999998098 ns/iter 1089.9584419828886 ns/iter 1.00
JSONSchema_Validate_Draft6_Property_Names 1849.1700439018157 ns/iter 1860.68308989559 ns/iter 0.99
JSONSchema_Validate_Draft7_If_Then_Else 548.7993750000848 ns/iter 561.8539285714113 ns/iter 0.98
JSONSchema_Compiler_Draft6_AdaptiveCard 10380249499.99999 ns/iter 10886091299.999863 ns/iter 0.95

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

Please sign in to comment.