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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 8u5
    • core-libs
    • x86
    • windows_2003

      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.


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

              Created:
              Updated:
              Resolved: