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

Simplify Optional implementation

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 13
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b16

      Description

      The current code for Optional.ofNullable() null-checks the value, then calls of(), which calls new Optional(), which null-checks again via Objects.requireNonNull(). This code can be simplified by refactoring so that we only null-check once and chain through fewer methods.

      The JIT is likely to inline all this and generate the optimal code, BUT it can fail to do so due inlining limits. Simplifying reduces the risk of that, while speeding up code executed during startup and warmup phases.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: