From 5773229ed023c50bf0fa1637618c6ffc64309d4e Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Wed, 22 Jan 2025 22:47:43 +0100 Subject: [PATCH] perf: Fewer JSON pointer lookups Signed-off-by: Dmitry Dygalo --- crates/jsonschema-referencing/src/registry.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/jsonschema-referencing/src/registry.rs b/crates/jsonschema-referencing/src/registry.rs index 0b420caf..7d8171e0 100644 --- a/crates/jsonschema-referencing/src/registry.rs +++ b/crates/jsonschema-referencing/src/registry.rs @@ -461,14 +461,8 @@ fn collect_external_resources( { continue; } - // Handle local references separately as they may have nested references to external resources - if reference.starts_with('#') { - if reference == "#" { - continue; - } - if let Some(referenced) = pointer(contents, reference.trim_start_matches('#')) { - collect_external_resources(base, referenced, collected, seen)?; - } + + if reference == "#" { continue; } @@ -480,6 +474,14 @@ fn collect_external_resources( return Ok(()); } + // Handle local references separately as they may have nested references to external resources + if reference.starts_with('#') { + if let Some(referenced) = pointer(contents, reference.trim_start_matches('#')) { + collect_external_resources(base, referenced, collected, seen)?; + } + continue; + } + let resolved = if base.has_fragment() { let mut base_without_fragment = base.clone(); base_without_fragment.set_fragment(None);