-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of StringUtils.isMixedCase() #1096
Improve performance of StringUtils.isMixedCase() #1096
Conversation
How do you know it's faster? Sometimes running a JMH test shows surprising results, and sometimes not ;-) |
In the best case only two iterations are needed instead of three. Whenever the string is mixed cases, it should take one iteration less. In the wirst case the performance should stay the same. But I agree, I should provide some data which support my theory. |
You could add a JMH benchmark to your PR |
@garydgregory as you surgeste, I wrote a small test.
As you could see, in every senorio I tested the code is between 1ns and 25ns per op faster. |
Hi @hduelme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hduelme
The new file is missing the Apache license header. See any other Java file.
Also, please rebase on master so we can make sure this PR builds properly. |
The changes optimize the mixed-case detecting function in StringUtils.java by reducing redundant character property checks. The loop will now return early when both uppercase and lowercase are present, preventing further unnecessary operations. It also introduces a local variable to store the character being checked, reducing the number of method calls to get the character. The end return statement is also simplified to return false, as the true condition has already been covered inside the loop.
d9ba517
to
fcedff2
Compare
@garydgregory rebased and license header added |
That was also surprising for me. But yes looks like it. |
Codecov Report
@@ Coverage Diff @@
## master #1096 +/- ##
=========================================
Coverage 92.21% 92.21%
+ Complexity 7551 7549 -2
=========================================
Files 197 197
Lines 15801 15802 +1
Branches 2923 2922 -1
=========================================
+ Hits 14571 14572 +1
Misses 660 660
Partials 570 570
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
The changes optimize the mixed-case detecting function in StringUtils.java by reducing redundant character property checks. The loop will now return early when both uppercase and lowercase are present, preventing further unnecessary operations. It also introduces a local variable to store the character being checked, reducing the number of method calls to get the character. The end return statement is also simplified to return false, as the true condition has already been covered inside the loop.