-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract
BundleOptions::WithoutIdentifiers
into its own `unidentify(…
…)` (#1429) Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
13 changed files
with
851 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <sourcemeta/jsontoolkit/jsonschema.h> | ||
|
||
namespace sourcemeta::jsontoolkit { | ||
|
||
auto unidentify(JSON &schema, const SchemaWalker &walker, | ||
const SchemaResolver &resolver, | ||
const std::optional<std::string> &default_dialect) -> void { | ||
// (1) Re-frame before changing anything | ||
Frame frame; | ||
frame.analyse(schema, walker, resolver, default_dialect); | ||
|
||
// (2) Remove all identifiers and anchors | ||
for (const auto &entry : | ||
SchemaIterator{schema, walker, resolver, default_dialect}) { | ||
auto &subschema{get(schema, entry.pointer)}; | ||
if (subschema.is_boolean()) { | ||
continue; | ||
} | ||
|
||
assert(entry.base_dialect.has_value()); | ||
anonymize(subschema, entry.base_dialect.value()); | ||
|
||
if (entry.vocabularies.contains( | ||
"https://json-schema.org/draft/2020-12/vocab/core")) { | ||
subschema.erase("$anchor"); | ||
subschema.erase("$dynamicAnchor"); | ||
} | ||
|
||
if (entry.vocabularies.contains( | ||
"https://json-schema.org/draft/2019-09/vocab/core")) { | ||
subschema.erase("$anchor"); | ||
subschema.erase("$recursiveAnchor"); | ||
} | ||
} | ||
|
||
// (3) Fix-up reference based on pointers from the root | ||
for (const auto &[key, reference] : frame.references()) { | ||
const auto result{frame.traverse(reference.destination)}; | ||
if (result.has_value()) { | ||
set(schema, key.second, | ||
JSON{to_uri(result.value().get().pointer).recompose()}); | ||
} else if (!key.second.empty() && key.second.back().is_property() && | ||
key.second.back().to_property() != "$schema") { | ||
set(schema, key.second, JSON{reference.destination}); | ||
} | ||
} | ||
} | ||
|
||
} // namespace sourcemeta::jsontoolkit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
55481f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark (linux/llvm)
JSON_Array_Of_Objects_Unique
443.41870124154434
ns/iter448.4770890754095
ns/iter0.99
JSON_Parse_1
30856.39630054861
ns/iter30090.83903109611
ns/iter1.03
JSON_Fast_Hash_Helm_Chart_Lock
54.717853651566976
ns/iter54.68786174052018
ns/iter1.00
JSON_Equality_Helm_Chart_Lock
150.29080986917077
ns/iter148.96340890249002
ns/iter1.01
Regex_Lower_S_Or_Upper_S_Asterisk
2.1813326640329915
ns/iter2.1981092509955573
ns/iter0.99
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar
2.1860155093271376
ns/iter2.183798040079222
ns/iter1.00
Regex_Period_Asterisk
2.181417065696179
ns/iter2.179099111927257
ns/iter1.00
Regex_Group_Period_Asterisk_Group
2.182036349715757
ns/iter2.1886055407645943
ns/iter1.00
Regex_Period_Plus
2.4914004008456194
ns/iter2.4881015864876015
ns/iter1.00
Regex_Period
2.506632647577241
ns/iter2.4873470862084837
ns/iter1.01
Regex_Caret_Period_Plus_Dollar
2.4887776977850873
ns/iter2.487497865191268
ns/iter1.00
Regex_Caret_Group_Period_Plus_Group_Dollar
2.489922474578475
ns/iter2.4871968080426234
ns/iter1.00
Regex_Caret_Period_Asterisk_Dollar
3.4192200934329176
ns/iter3.4189465014347107
ns/iter1.00
Regex_Caret_Group_Period_Asterisk_Group_Dollar
3.418952737835449
ns/iter3.4175378116971133
ns/iter1.00
Regex_Caret_X_Hyphen
12.504706843113246
ns/iter12.527434995876682
ns/iter1.00
Regex_Period_Md_Dollar
74.05161340026288
ns/iter73.57518787834836
ns/iter1.01
Regex_Caret_Slash_Period_Asterisk
7.093413433351044
ns/iter7.1460825934591305
ns/iter0.99
Regex_Caret_Period_Range_Dollar
2.5058175069195956
ns/iter3.748331126870648
ns/iter0.67
Regex_Nested_Backtrack
506.3542772193359
ns/iter493.74734527764986
ns/iter1.03
Pointer_Object_Traverse
44.90762013352479
ns/iter44.77268042194476
ns/iter1.00
Pointer_Object_Try_Traverse
52.26983470377153
ns/iter52.346571993886705
ns/iter1.00
Pointer_Push_Back_Pointer_To_Weak_Pointer
352.297219581662
ns/iter352.87085163843483
ns/iter1.00
This comment was automatically generated by workflow using github-action-benchmark.
55481f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark (macos/llvm)
JSON_Array_Of_Objects_Unique
407.459216519292
ns/iter330.43087146073617
ns/iter1.23
JSON_Parse_1
25862.212085917818
ns/iter21221.843152698468
ns/iter1.22
JSON_Fast_Hash_Helm_Chart_Lock
57.95479504845729
ns/iter47.69326086406976
ns/iter1.22
JSON_Equality_Helm_Chart_Lock
154.35157276779012
ns/iter133.06913206316509
ns/iter1.16
Regex_Lower_S_Or_Upper_S_Asterisk
1.7515113674257687
ns/iter1.5689222735977724
ns/iter1.12
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar
1.7316679848811976
ns/iter1.5720424518240115
ns/iter1.10
Regex_Period_Asterisk
1.8475199273979472
ns/iter1.5849100255488364
ns/iter1.17
Regex_Group_Period_Asterisk_Group
1.6977302224322826
ns/iter1.619187085412587
ns/iter1.05
Regex_Period_Plus
2.4910686245373266
ns/iter1.8939170674439665
ns/iter1.32
Regex_Period
2.165795449841771
ns/iter2.091953773469908
ns/iter1.04
Regex_Caret_Period_Plus_Dollar
2.0989762475510423
ns/iter1.976951513751499
ns/iter1.06
Regex_Caret_Group_Period_Plus_Group_Dollar
2.071488316107489
ns/iter2.015001725966835
ns/iter1.03
Regex_Caret_Period_Asterisk_Dollar
1.7085505559815002
ns/iter1.6003665135146479
ns/iter1.07
Regex_Caret_Group_Period_Asterisk_Group_Dollar
1.6682543585173972
ns/iter1.5698904069141555
ns/iter1.06
Regex_Caret_X_Hyphen
6.564934534701128
ns/iter6.306310681506139
ns/iter1.04
Regex_Period_Md_Dollar
71.20947022637732
ns/iter67.78072380757295
ns/iter1.05
Regex_Caret_Slash_Period_Asterisk
7.5654015303254845
ns/iter6.3807192263469545
ns/iter1.19
Regex_Caret_Period_Range_Dollar
2.142386520023517
ns/iter2.046429970595506
ns/iter1.05
Regex_Nested_Backtrack
773.3462000510282
ns/iter726.0965320237835
ns/iter1.07
Pointer_Object_Traverse
15.725582600629465
ns/iter14.844123704205458
ns/iter1.06
Pointer_Object_Try_Traverse
35.45585758590162
ns/iter31.284784202430174
ns/iter1.13
Pointer_Push_Back_Pointer_To_Weak_Pointer
181.87580669859832
ns/iter172.65156969807174
ns/iter1.05
This comment was automatically generated by workflow using github-action-benchmark.
55481f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark (windows/msvc)
JSON_Array_Of_Objects_Unique
419.10147843102794
ns/iter416.14630386214554
ns/iter1.01
JSON_Parse_1
81309.16294643495
ns/iter79599.30360252195
ns/iter1.02
JSON_Fast_Hash_Helm_Chart_Lock
56.79349107143342
ns/iter54.34384999999793
ns/iter1.05
JSON_Equality_Helm_Chart_Lock
214.83100000001087
ns/iter219.54805269875777
ns/iter0.98
Regex_Lower_S_Or_Upper_S_Asterisk
8.09690219599542
ns/iter8.154109785026717
ns/iter0.99
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar
7.924672732480097
ns/iter8.172507812501198
ns/iter0.97
Regex_Period_Asterisk
7.952081473214482
ns/iter7.840069196428497
ns/iter1.01
Regex_Group_Period_Asterisk_Group
7.992249999999907
ns/iter7.934264696722221
ns/iter1.01
Regex_Period_Plus
7.929559786028484
ns/iter7.777581661707126
ns/iter1.02
Regex_Period
8.11947433035698
ns/iter7.850442822096568
ns/iter1.03
Regex_Caret_Period_Plus_Dollar
8.000271205356972
ns/iter7.767732142857246
ns/iter1.03
Regex_Caret_Group_Period_Plus_Group_Dollar
8.38834549826642
ns/iter8.743973214285614
ns/iter0.96
Regex_Caret_Period_Asterisk_Dollar
8.303265625000073
ns/iter7.933832107439376
ns/iter1.05
Regex_Caret_Group_Period_Asterisk_Group_Dollar
8.224844159711257
ns/iter8.064123178284392
ns/iter1.02
Regex_Caret_X_Hyphen
11.618403571428562
ns/iter11.977482142857607
ns/iter0.97
Regex_Period_Md_Dollar
145.94708723451558
ns/iter143.47674805907258
ns/iter1.02
Regex_Caret_Slash_Period_Asterisk
11.775487499999063
ns/iter11.82410178571404
ns/iter1.00
Regex_Caret_Period_Range_Dollar
9.086469602291999
ns/iter9.251618262268787
ns/iter0.98
Regex_Nested_Backtrack
588.6363392856911
ns/iter592.2207142856248
ns/iter0.99
Pointer_Object_Traverse
56.69698214285899
ns/iter55.9038800000053
ns/iter1.01
Pointer_Object_Try_Traverse
76.37816964285449
ns/iter75.9869531250068
ns/iter1.01
Pointer_Push_Back_Pointer_To_Weak_Pointer
175.17648494484808
ns/iter191.80450819683765
ns/iter0.91
This comment was automatically generated by workflow using github-action-benchmark.
55481f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark (linux/gcc)
Pointer_Object_Traverse
44.323071200537065
ns/iter44.315735461146176
ns/iter1.00
Pointer_Object_Try_Traverse
22.409523536155056
ns/iter22.4184684058889
ns/iter1.00
Pointer_Push_Back_Pointer_To_Weak_Pointer
213.00843352003835
ns/iter216.25236959070153
ns/iter0.98
Regex_Lower_S_Or_Upper_S_Asterisk
3.1354589423323262
ns/iter2.4868763559190525
ns/iter1.26
Regex_Caret_Lower_S_Or_Upper_S_Asterisk_Dollar
3.1236844399220987
ns/iter2.4883152921491214
ns/iter1.26
Regex_Period_Asterisk
3.1244189730837797
ns/iter2.4896222895821816
ns/iter1.25
Regex_Group_Period_Asterisk_Group
3.124149829439447
ns/iter2.495235746444008
ns/iter1.25
Regex_Period_Plus
3.1251358316953213
ns/iter2.797069635064368
ns/iter1.12
Regex_Period
3.1283836481291374
ns/iter2.798695325674326
ns/iter1.12
Regex_Caret_Period_Plus_Dollar
3.1256782396702962
ns/iter2.796517724700727
ns/iter1.12
Regex_Caret_Group_Period_Plus_Group_Dollar
3.1257985513587023
ns/iter2.8251081758681287
ns/iter1.11
Regex_Caret_Period_Asterisk_Dollar
3.126567055852649
ns/iter2.488767658546089
ns/iter1.26
Regex_Caret_Group_Period_Asterisk_Group_Dollar
3.1302327364697122
ns/iter2.493301441550906
ns/iter1.26
Regex_Caret_X_Hyphen
12.43179876404824
ns/iter13.05201626475827
ns/iter0.95
Regex_Period_Md_Dollar
89.63427958149308
ns/iter93.39210618283377
ns/iter0.96
Regex_Caret_Slash_Period_Asterisk
7.1531579424733405
ns/iter6.216727963282871
ns/iter1.15
Regex_Caret_Period_Range_Dollar
3.185703537765074
ns/iter4.043306672425007
ns/iter0.79
Regex_Nested_Backtrack
813.1069888583747
ns/iter819.5413688749217
ns/iter0.99
JSON_Array_Of_Objects_Unique
377.73481002123015
ns/iter401.9023872448747
ns/iter0.94
JSON_Parse_1
32810.163484040466
ns/iter32681.681430524735
ns/iter1.00
JSON_Fast_Hash_Helm_Chart_Lock
63.95427803930726
ns/iter58.04574385832107
ns/iter1.10
JSON_Equality_Helm_Chart_Lock
142.6291877626806
ns/iter143.1157399725114
ns/iter1.00
This comment was automatically generated by workflow using github-action-benchmark.