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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 18
    • Affects Version/s: None
    • Component/s: core-libs
    • None

      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.

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

              Created:
              Updated:
              Resolved: