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

Simplify Optional implementation

XMLWordPrintable

    • b16

      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.

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

              Created:
              Updated:
              Resolved: