This PR includes some StringUtils methods optimization. The problem is that trimLeading/TrailingCharacter and trimLeading/TrailingWhitespace methods create a StringBuilder object as a local var instead of using String.substring method. Such approach is leading to unnecessary object creation on every method invocation. Also it runs slower because of internal StringBuilder operations and conversions String->StringBuilder->String. According to simple JMH benchmark, substring is x2/x3 faster on avg scenarios. The situation with long strings that are not changed at all(if the method returns an equal string) is especially dramatic for StringBuilder (but substring will return its param instead of new a string creation) Also found out that trimWhitespace(String str) method is already implemented in similar style.
Comment From: pivotal-issuemaster
@Shenker93 Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-issuemaster
@Shenker93 Thank you for signing the Contributor License Agreement!