File tree Expand file tree Collapse file tree 5 files changed +16
-11
lines changed
benchmark/src/jvmMain/kotlin/io/github/optimumcode/json/schema/benchmark
json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json Expand file tree Collapse file tree 5 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,9 @@ abstract class AbstractComparisonBenchmark {
136136 return errors
137137 }
138138
139+ @Benchmark
140+ fun validateKmpBasic (): ValidationOutput .Basic = schema.validate(document, OutputCollector .basic())
141+
139142 @Benchmark
140143 fun validateKmpFlag (): ValidationOutput .Flag = schema.validate(document, OutputCollector .flag())
141144
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ public sealed class JsonPointer(
174174 node = node.next
175175 }
176176 if (result == 0 ) {
177- // just in case if for some reason the resulting has is zero
177+ // just in case if for some reason the resulting hash is zero
178178 // this way we won't recalculate it again
179179 result = 31
180180 }
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ private class PatternAssertion(
5858 for ((prop, value) in element) {
5959 val matchedRegex =
6060 assertionsByRegex.filter { (regex) ->
61- regex.find (prop) != null
61+ regex.containsMatchIn (prop)
6262 }
6363 if (matchedRegex.isEmpty()) {
6464 continue
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import kotlinx.serialization.json.JsonArray
1212import kotlinx.serialization.json.JsonElement
1313import kotlinx.serialization.json.JsonObject
1414import kotlinx.serialization.json.JsonPrimitive
15+ import kotlin.math.max
1516
1617@Suppress(" unused" )
1718internal object RequiredAssertionFactory : AbstractAssertionFactory(" required" ) {
@@ -45,9 +46,13 @@ private class RequiredAssertion(
4546 return @use true
4647 }
4748 val missingProperties =
48- requiredProperties.asSequence()
49- .filter { ! element.containsKey(it) }
50- .toSet()
49+ if (element.isEmpty()) {
50+ requiredProperties
51+ } else {
52+ val keys = element.keys
53+ requiredProperties
54+ .filterNotTo(HashSet (max(requiredProperties.size / 2 , 1 ))) { it in keys }
55+ }
5156 if (missingProperties.isEmpty()) {
5257 return @use true
5358 }
Original file line number Diff line number Diff line change @@ -6,9 +6,6 @@ import kotlinx.serialization.json.JsonNull
66import kotlinx.serialization.json.JsonObject
77import kotlinx.serialization.json.JsonPrimitive
88import kotlinx.serialization.json.booleanOrNull
9- import kotlinx.serialization.json.jsonArray
10- import kotlinx.serialization.json.jsonObject
11- import kotlinx.serialization.json.jsonPrimitive
129
1310internal fun areEqual (
1411 first : JsonElement ,
@@ -18,9 +15,9 @@ internal fun areEqual(
1815 return false
1916 }
2017 return when (first) {
21- is JsonObject -> areEqualObjects(first, second.jsonObject )
22- is JsonArray -> areEqualArrays(first, second.jsonArray )
23- is JsonPrimitive -> areEqualPrimitives(first, second.jsonPrimitive )
18+ is JsonObject -> areEqualObjects(first, second as JsonObject )
19+ is JsonArray -> areEqualArrays(first, second as JsonArray )
20+ is JsonPrimitive -> areEqualPrimitives(first, second as JsonPrimitive )
2421 }
2522}
2623
You can’t perform that action at this time.
0 commit comments