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

Improve java.lang.invoke.MethodType.parameterList() and its usage

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • None
    • 18
    • core-libs
    • None

    Description

      Currently the method is implemented like

      public List<Class<?>> parameterList() {
        return Collections.unmodifiableList(Arrays.asList(ptypes.clone()));
      }

      This seems to be excessive, as three objects are allocated here. Instead we can use List.of(ptypes) which doesn't allocate anything for empty array and for one of length 1 and 2 allocates lightweight objects with 1 and two fields respectively still copying longer arrays. This is likely to be fruitful as most of methods have 0-2 parameters.

      Also there is a couple of cases when MethodType.parameterLis() is called to get its size, which is excessive either as we can use MethodType.parameterCount() instead.

      Attachments

        Issue Links

          Activity

            People

              stsypanov Sergey Tsypanov
              stsypanov Sergey Tsypanov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: