Skip to content

StringUtils.trimAllWhitespace(String str) is slow. #562

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

Closed
wants to merge 2 commits into from

Conversation

hengyunabc
Copy link
Contributor

StringUtils.trimAllWhitespace(String str) is slow.
Using sb.deleteCharAt(index) is not a good idea, it will call
System.arraycopy(value, index+1, value, index, count-index-1);

Test:
https://gist.github.com/hengyunabc/a4651e90db24cc5ed29a

I have signed and agree to the terms of the SpringSource Individual
Contributor License Agreement.

StringUtils.trimAllWhitespace(String str) is slow.
Using sb.deleteCharAt(index) is not a good idea, it will call 
System.arraycopy(value, index+1, value, index, count-index-1);

Test:
https://gist.github.com/hengyunabc/a4651e90db24cc5ed29a
@snicoll snicoll self-assigned this Jun 13, 2014
snicoll added a commit that referenced this pull request Jun 13, 2014
* pull562:
  Improve StringUtils#trimAllWhitespace
@snicoll
Copy link
Member

snicoll commented Jun 13, 2014

Thanks for the contribution! Looking a bit closer, I slightly change the code to improve it further. This has been merged to master.

@snicoll snicoll closed this Jun 13, 2014
@hengyunabc
Copy link
Contributor Author

I hava updated the test:
https://gist.github.com/hengyunabc/a4651e90db24cc5ed29a

It seems that myTrimAllWhitespace2 is a better algrithom.
If consider about Unocide, like myTrimAllWhitespaceUnicode, it will be very slow.

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