commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernd Eckenfels (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LANG-1058) StringUtils.uncapitalize performance improvement
Date Sun, 26 Oct 2014 17:30:34 GMT

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

Bernd Eckenfels edited comment on LANG-1058 at 10/26/14 5:30 PM:
-----------------------------------------------------------------

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}

Not sure if this would actually change the semantic a bit (as toLowerCase works on uppercase
and titlecase). But I would argue it is the better semantic anyway.

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


was (Author: b.eckenfels):
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)

Mime
View raw message