harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Wu" <wuyue...@gmail.com>
Subject [classlib][performance]The case mapping operation could be simplify
Date Mon, 15 Jan 2007 08:29:21 GMT
I found some String.toLower(Upper)Case are invoked in some place which
is not necessay at all.

As you know, String.toLower(Upper)Case will perform locale-sensitive
mappings, context-sensitive mappings, and 1:M character mappings. It
is expensive I think. In almost all of the conditions, following
method[1] is good enough.


For example, there is following line in java.net.URL,
protocol = protocol.toLowerCase();
But according to RFC 2396, the scheme is defined by "alpha *( alpha |
digit | "+" | "-" | "." )"

And another example is the Locale,
countryCode = country.toUpperCase();
But country code is defined as ASCII character only.

So I'd like to add methods like [1] to org.apache.harmony.luni.util
and refactor every possible place to use it. please correct me if I am
wrong, any concerns are welcome.

[1]
public static String toLowerCase(String s){
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if ('A' <= c && c <= 'Z') {
                buffer.append((char) (c + ('a' - 'A')));
            }else{
                buffer.append(c);
            }
        }
        return buffer.toString();
    }

-- 
Tony Wu
China Software Development Lab, IBM

Mime
View raw message