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

Simplify Optional implementation

    XMLWordPrintable

Details

    • 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

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

            Dates

              Created:
              Updated:
              Resolved: