commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johann (JIRA)" <j...@apache.org>
Subject [jira] Created: (LANG-322) ClassUtils.getShortClassName(String) inefficient
Date Wed, 14 Feb 2007 10:03:05 GMT
ClassUtils.getShortClassName(String) inefficient
------------------------------------------------

                 Key: LANG-322
                 URL: https://issues.apache.org/jira/browse/LANG-322
             Project: Commons Lang
          Issue Type: Improvement
    Affects Versions: 2.3
            Reporter: Johann


ClassUtils.getShortClassName(String) is inefficient because it clones the Class name's char
array which is then cloned again in the String(char[], int, int) constructor. Most of this
garbage can be avoided.

Proposed fix:

public static String getShortClassName(String className) {
 [Null and empty checks]
 int lastDotIdx = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
 int innerIdx = className.indexOf(INNER_CLASS_SEPARATOR_CHAR, lastDotIdx == -1 ? 0 : lastDotIdx
+ 1);
 String out = result.substring(++lastDotIdx);
 if (innerIdx != -1) {
  out = out.replace(INNER_CLASS_SEPARATOR_CHAR, PACKAGE_SEPARATOR_CHAR);
 }
 return out;
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message