Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-322

ClassUtils.getShortClassName(String) inefficient

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3
    • 2.4
    • 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)

      { out = out.replace(INNER_CLASS_SEPARATOR_CHAR, PACKAGE_SEPARATOR_CHAR); }

      return out;
      }

      Attachments

        1. LANG-322.patch
          1 kB
          Ben Speakmon

        Activity

          People

            Unassigned Unassigned
            johann Johann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: