Skip to content

Comparables::assertIsBetween String alloc. removed - #2884

Closed
DirkToewe wants to merge 1 commit into
assertj:mainfrom
DirkToewe:main
Closed

DirkToewe wants to merge 1 commit into
assertj:mainfrom
DirkToewe:main

Conversation

@DirkToewe

Copy link
Copy Markdown
Contributor

Comparables::checkBoundsValidity, which is used by Comparables::assertIsBetween, does build an error message String even if the assertion does not fail. This results in noticeable overhead. The JVM can hardly eliminate the String building since start.toString(), operator.toString() and end.toString() may have side effects.

This PR moves the String building inside a Supplier<String> which is only evaluated on failure.

Comparables::checkBoundsValidity, which is used by Comparables::assertIsBetween, does build an error message String even if the assertion does not fail. This results in noticeable overhead. The JVM can hardly eliminate the String building since `start.toString()`, `operator.toString()` and `end.toString()` may have side effects. This commit moves the String building inside a `Supplier<String>` which is only evaluated on failure.
@joel-costigliola

Copy link
Copy Markdown
Member

Integrated thanks @DirkToewe!

@joel-costigliola joel-costigliola added this to the 3.24.0 milestone Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants