Implement lazy evaluation for custom message expression#14
Merged
Conversation
Previously, assert($cond, $msg) always evaluated the message expression
even when the condition was true. This caused unnecessary performance
overhead when using expensive computations in error messages.
Now the message expression is lazily evaluated using OP_OR, equivalent to:
$cond || do { croak($msg) }
This means expensive_debug_info() in assert($x > 0, expensive_debug_info())
is NOT called when $x > 0, improving performance and preventing unwanted
side effects.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Pull Request Test Coverage Report for Build 20052858643Details
💛 - Coveralls |
kfly8
added a commit
that referenced
this pull request
Dec 9, 2025
Changelog diff is: diff --git a/Changes b/Changes index b9e7aba..6d909ea 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for Perl extension Syntax-Keyword-Assert {{$NEXT}} +0.18 2025-12-09T05:21:47Z + - Implement lazy evaluation for custom message expression #14 + 0.17 2025-12-08T13:44:46Z - Add custom error message support #11 - Fix test failures on Windows and older Perl #13
kfly8
added a commit
that referenced
this pull request
Dec 13, 2025
Changelog diff is: diff --git a/Changes b/Changes index 6d909ea..d385574 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for Perl extension Syntax-Keyword-Assert {{$NEXT}} +0.19 2025-12-13T12:48:19Z + - Fixed failed test #15 + 0.18 2025-12-09T05:21:47Z - Implement lazy evaluation for custom message expression #14
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.
Problem
Previously,
assert($cond, $msg)always evaluated the message expression even when the condition was true:This caused:
Solution
Changed the implementation to use
OP_ORfor lazy evaluation, equivalent to:Now the message expression is only evaluated when the assertion fails.
🤖 Generated with Claude Code