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 {
136
136
return errors
137
137
}
138
138
139
+ @Benchmark
140
+ fun validateKmpBasic (): ValidationOutput .Basic = schema.validate(document, OutputCollector .basic())
141
+
139
142
@Benchmark
140
143
fun validateKmpFlag (): ValidationOutput .Flag = schema.validate(document, OutputCollector .flag())
141
144
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ public sealed class JsonPointer(
174
174
node = node.next
175
175
}
176
176
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
178
178
// this way we won't recalculate it again
179
179
result = 31
180
180
}
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ private class PatternAssertion(
58
58
for ((prop, value) in element) {
59
59
val matchedRegex =
60
60
assertionsByRegex.filter { (regex) ->
61
- regex.find (prop) != null
61
+ regex.containsMatchIn (prop)
62
62
}
63
63
if (matchedRegex.isEmpty()) {
64
64
continue
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import kotlinx.serialization.json.JsonArray
12
12
import kotlinx.serialization.json.JsonElement
13
13
import kotlinx.serialization.json.JsonObject
14
14
import kotlinx.serialization.json.JsonPrimitive
15
+ import kotlin.math.max
15
16
16
17
@Suppress(" unused" )
17
18
internal object RequiredAssertionFactory : AbstractAssertionFactory(" required" ) {
@@ -45,9 +46,13 @@ private class RequiredAssertion(
45
46
return @use true
46
47
}
47
48
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
+ }
51
56
if (missingProperties.isEmpty()) {
52
57
return @use true
53
58
}
Original file line number Diff line number Diff line change @@ -6,9 +6,6 @@ import kotlinx.serialization.json.JsonNull
6
6
import kotlinx.serialization.json.JsonObject
7
7
import kotlinx.serialization.json.JsonPrimitive
8
8
import kotlinx.serialization.json.booleanOrNull
9
- import kotlinx.serialization.json.jsonArray
10
- import kotlinx.serialization.json.jsonObject
11
- import kotlinx.serialization.json.jsonPrimitive
12
9
13
10
internal fun areEqual (
14
11
first : JsonElement ,
@@ -18,9 +15,9 @@ internal fun areEqual(
18
15
return false
19
16
}
20
17
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 )
24
21
}
25
22
}
26
23
You can’t perform that action at this time.
0 commit comments