Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3
-
None
-
None
Description
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)
return out;
}