You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bernd Eckenfels (JIRA)" <ji...@apache.org> on 2014/10/26 18:26:33 UTC

[jira] [Commented] (LANG-1058) StringUtils.uncapitalize performance improvement

    [ https://issues.apache.org/jira/browse/LANG-1058?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14184553#comment-14184553 ] 

Bernd Eckenfels commented on LANG-1058:
---------------------------------------

Do you mean the possible improvement of skipping one char operation, like:

{code}
    public static String uncapitalize(final String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }

        final char firstChar = str.charAt(0);
        final char newChar = Character.toLowerCase(firstChar);
        if (firstChar == newChar) {
            // already uncapitalized
            return str;
        }

        return new StringBuilder(strLen)
            .append(newChar)
            .append(str.substring(1))
            .toString();
    }
{code}

(I dont think repacing Stringbuilder with ""+"" is a good thing here as we know the target string size and can optimize for it)

> StringUtils.uncapitalize performance improvement
> ------------------------------------------------
>
>                 Key: LANG-1058
>                 URL: https://issues.apache.org/jira/browse/LANG-1058
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: Leo Wang
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)