Optimize boolean operations#527
Merged
Merged
Conversation
JesusValeraDev
approved these changes
Nov 30, 2025
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.
📚 Description
Performance optimization for boolean operations in the assertion guard system. This PR replaces string-based boolean comparisons with integer arithmetic, which is significantly faster in Bash.
🔖 Changes
1. Replace boolean strings with integers (
src/state.sh)Changed
_ASSERTION_FAILED_IN_TESTfrom string"true"/"false"to integer1/0:Why this matters: Integer comparison using arithmetic evaluation
(( var ))is faster than string comparison[[ "$var" == "true" ]]because:2. Inline the guard check in all assertion functions (
src/assert.sh,src/bashunit.sh)Replaced function calls with direct inline arithmetic checks:
Why this matters:
assert::guard→state::is_assertion_failed_in_test)3. Extract and reuse
str::strip_ansifunction (src/str.sh)Created a dedicated function to strip ANSI escape codes and reused it across the codebase:
This consolidates the duplicated ANSI stripping logic that was previously inline in
assert_equals,assert_not_equals, andstr::rpad, combining two separate operations (ANSI removal + control char removal) into a single sed command.✅ To-do list
CHANGELOG.mdto reflect the new feature or fix