Skip to content

Commit

Permalink
short-circuit SchemaNode.is_valid
Browse files Browse the repository at this point in the history
there's an optimization already for just one validator, perhaps, we should short-circuit as well as soon as one validator is not valid
  • Loading branch information
jqnatividad committed Oct 26, 2024
1 parent 194e9a7 commit b10b014
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/jsonschema/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ impl Validate for SchemaNode {
kvs.validators[0].1.is_valid(instance)
}
NodeValidators::Keyword(kvs) => {
kvs.validators.iter().all(|(_, v)| v.is_valid(instance))
for (_, v) in &kvs.validators {
if !v.is_valid(instance) {
return false;
}
}
true
}
NodeValidators::Array { validators } => validators.iter().all(|v| v.is_valid(instance)),
NodeValidators::Boolean { validator: Some(_) } => false,
Expand Down

0 comments on commit b10b014

Please sign in to comment.