Author: djones Date: Wed Apr 15 19:59:50 2015 New Revision: 1673944 URL: http://svn.apache.org/r1673944 Log: Updates for LANG-1058: StringUtils.uncapitalize performance improvement. Similar fix also applied to StringUtils.capitalize (as mentioned in issue). Thanks to Leo Wang.
Modified: commons/proper/lang/trunk/src/changes/changes.xml commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Modified: commons/proper/lang/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1673944&r1=1673943&r2=1673944&view=diff ============================================================================== --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original) +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Wed Apr 15 19:59:50 2015 @@ -22,6 +22,7 @@ <body> <release version="3.5" date="tba" description="tba"> + <action issue="LANG-1058" type="update" dev="djones" due-to="Leo Wang">StringUtils.uncapitalize performance improvement</action> <action issue="LANG-1069" type="update" dev="djones" due-to="Arno Noordover">CharSet.getInstance documentation does not clearly explain how to include negation character in set</action> <action issue="LANG-1050" type="add" dev="djones" due-to="James Sawle">Change nullToEmpty methods to generics</action> <action issue="LANG-1111" type="fix" dev="chas">Fix FindBugs warnings in DurationFormatUtils</action> Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=1673944&r1=1673943&r2=1673944&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Wed Apr 15 19:59:50 2015 @@ -5716,15 +5716,16 @@ public class StringUtils { } final char firstChar = str.charAt(0); - if (Character.isTitleCase(firstChar)) { + final char newChar = Character.toUpperCase(firstChar); + if (firstChar == newChar) { // already capitalized return str; } - return new StringBuilder(strLen) - .append(Character.toTitleCase(firstChar)) - .append(str.substring(1)) - .toString(); + char[] newChars = new char[strLen]; + newChars[0] = newChar; + str.getChars(1,strLen, newChars, 1); + return String.valueOf(newChars); } /** @@ -5755,15 +5756,16 @@ public class StringUtils { } final char firstChar = str.charAt(0); - if (Character.isLowerCase(firstChar)) { + final char newChar = Character.toLowerCase(firstChar); + if (firstChar == newChar) { // already uncapitalized return str; } - return new StringBuilder(strLen) - .append(Character.toLowerCase(firstChar)) - .append(str.substring(1)) - .toString(); + char[] newChars = new char[strLen]; + newChars[0] = newChar; + str.getChars(1,strLen, newChars, 1); + return String.valueOf(newChars); } /**