You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2007/02/14 21:48:05 UTC

[jira] Updated: (LANG-322) ClassUtils.getShortClassName(String) inefficient

     [ https://issues.apache.org/jira/browse/LANG-322?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-322:
-------------------------------

    Fix Version/s: 3.0

This seems valid - the included code removes a .toCharArray and a new String by using the String API.

The only change stylistically I'd want is to get the ++lastDotIdx out and onto the previous line for readability.

> 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
>             Fix For: 3.0
>
>
> 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