Repository navigation
Skip scalar descendants in JSONPath recursive descent - #1717
Conversation
| calc_data: &mut PathCalculatorData<'_, 'j, S, UPTG::PT>, | ||
| ) -> ControlFlow<()> { | ||
| // These selectors match nothing on a scalar, so scalar descendants can be skipped. | ||
| let needs_container = matches!( |
There was a problem hiding this comment.
needs_container is always true here, since the grammar only allows literal | all | [bracket] after .. and bracket is exactly these six rules, so please drop the peek() check or change the comment to say it guards selectors that might be added later.
| val.get_type(), | ||
| SelectValueType::Object | SelectValueType::Array | ||
| ); | ||
| if !is_container && needs_container { |
There was a problem hiding this comment.
If needs_container goes away, this can be an unconditional if !is_container { continue; }.
| calc_data, | ||
| )?; | ||
| self.calc_full_scan(pairs.clone(), val, path_tracker, calc_data)?; | ||
| if is_container { |
There was a problem hiding this comment.
This check can never be false, because scalar children already hit the continue anove, so please call calc_full_scan directly.
AvivDavid23
left a comment
There was a problem hiding this comment.
Thanks for the addition! Please check the comments
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1717 +/- ##
==========================================
- Coverage 88.14% 88.13% -0.02%
==========================================
Files 18 18
Lines 6851 6861 +10
==========================================
+ Hits 6039 6047 +8
- Misses 812 814 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@g4lb can you rebase your branch to master? |
|
@AvivDavid23 Done. I rebased it on master. |
5f2cb79 to
239e184
Compare
AvivDavid23
left a comment
There was a problem hiding this comment.
Thank you for the contribution! approving
After
$.., a key,*, list, slice or filter selector matches only inside an object or array. For these selectors,calc_full_scannow skips scalar children. The results, order and paths do not change.$..author(IValue)$..author(serde_json)$..author,calc_once_paths$..*(IValue)cargo test -p json_pathpasses.Note
Low Risk
Single localized change in traversal logic with explicit semantic justification and broad equivalence testing; no API or output contract changes intended.
Overview
Recursive descent (
$..) no longer walks into scalar child nodes when continuing the scan under objects and arrays. Incalc_full_scan, descendants that are not objects or arrays are skipped beforecalc_internaland furthercalc_full_scancalls, because selectors after..cannot match inside scalars.This is a behavior-preserving optimization: match sets, order, and paths stay the same (validated against a large random corpus), with roughly 30–47% faster benchmarks on paths like
$..authorand$..*on large documents.Reviewed by Cursor Bugbot for commit 239e184. Bugbot is set up for automated code reviews on this repo. Configure here.