Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8170595

Optimize Class.isAnonymousClass, isLocalClass, and isMemberClass

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b149
    • Verification:
      Not verified

      Description

      Class.isAnonymousClass is implemented as:

          public boolean isAnonymousClass() {
              return "".equals(getSimpleName());
          }

      However, getSimpleName generates quite a few superfluous objects that could be avoided if isAnonymousClass was implemented to check the conditions that will lead it to return "" more directly:

          public boolean isAnonymousClass() {
              return !isArray() && getEnclosingMethodInfo() != null &&
                      getSimpleBinaryName0() == null;
          }

      This reduces the average cost of isAnonymousClass by around 65%, which should be worthwhile since this is both a public API and a component of other internal methods in wide internal use.

        Attachments

          Activity

            People

            • Assignee:
              redestad Claes Redestad
              Reporter:
              redestad Claes Redestad
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: