JMESPath short circuit or and operator#698
Merged
danielaparker merged 3 commits intodanielaparker:jmespath_binary_opfrom Apr 21, 2026
Merged
Conversation
3 tasks
e837e0f
into
danielaparker:jmespath_binary_op
37 checks passed
Owner
|
Nice! I've merged this PR into the branch jmespath_binary_op where I'll have the opportunity to study it more carefully and make sure there's sufficient test coverage for the different possibilities on the left and right sides. |
Author
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code change to short circuit the logical and
&&and or||operators:lhs && rhs: if lhs is false, return it without evaluating rhslhs || rhs: if lhs is true, return it without evaluating rhsFor this change, I made an operator_base as base class for the unary (not
!) and binary (comparators==,<, etc.) operators and a new logical (and&&and or||) operator. operator_base has a single interface: operator_base::evaluate takes a reference val and a vector of expressions, which contains 1 expression for the unary and 2 expressions [lhs, rhs] for the binary and logical operators.To hold this vector, I introduced the operator_expression which references an operator_base and is the owner of a vector of expressions. When evaluating, operator_expression::evaluate forwards the value it gets plus the expressions it owns to the operator_base.
The compilation happens as follows: