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

(array) Arrays.equals(Object[], Object[]) should be smarter about calling Object.equals

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P5
    • Resolution: Duplicate
    • Affects Version/s: 8u5
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2003

      Description

      A DESCRIPTION OF THE REQUEST :
      In the implementation of java.util.Arrays.equals(Object[], Object[]), the loop calls Object.equals for every pair of non-null objects.

              for (int i=0; i<length; i++) {
                  Object o1 = a[i];
                  Object o2 = a2[i];
                  if (!(o1==null ? o2==null : o1.equals(o2)))
                      return false;
              }

      The following (in the manner of java.util.Objects.equals) would be faster, because it would skip calling equals for all pairs that are simply ==.

              for (int i=0; i<length; i++) {
                  Object o1 = a[i];
                  Object o2 = a2[i];
                  if (o1 != o2 && (o1 == null || !o1.equals(o2)))
                      return false;
              }

      JUSTIFICATION :
      Widely used utility methods like this should have best-possible optimization because this can benefit many programs.


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bchristi Brent Christian
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: