< prev index next >

src/java.base/share/classes/jdk/internal/util/ArraysSupport.java

Print this page

        

@@ -163,10 +163,12 @@
 
     public static int mismatch(boolean[] a,
                                boolean[] b,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 7) {
             i = vectorizedMismatch(
                     a, Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
                     b, Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
                     length, LOG2_ARRAY_BOOLEAN_INDEX_SCALE);

@@ -183,10 +185,12 @@
 
     public static int mismatch(boolean[] a, int aFromIndex,
                                boolean[] b, int bFromIndex,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 7) {
             int aOffset = Unsafe.ARRAY_BOOLEAN_BASE_OFFSET + aFromIndex;
             int bOffset = Unsafe.ARRAY_BOOLEAN_BASE_OFFSET + bFromIndex;
             i = vectorizedMismatch(
                     a, aOffset,

@@ -225,10 +229,12 @@
         // ISSUE: defer to index receiving methods if performance is good
         // assert length <= a.length
         // assert length <= b.length
 
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 7) {
             i = vectorizedMismatch(
                     a, Unsafe.ARRAY_BYTE_BASE_OFFSET,
                     b, Unsafe.ARRAY_BYTE_BASE_OFFSET,
                     length, LOG2_ARRAY_BYTE_INDEX_SCALE);

@@ -272,10 +278,12 @@
         // assert 0 <= bFromIndex < b.length
         // assert 0 <= bFromIndex + length <= b.length
         // assert length >= 0
 
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 7) {
             int aOffset = Unsafe.ARRAY_BYTE_BASE_OFFSET + aFromIndex;
             int bOffset = Unsafe.ARRAY_BYTE_BASE_OFFSET + bFromIndex;
             i = vectorizedMismatch(
                     a, aOffset,

@@ -297,10 +305,12 @@
 
     public static int mismatch(char[] a,
                                char[] b,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 3) {
             i = vectorizedMismatch(
                     a, Unsafe.ARRAY_CHAR_BASE_OFFSET,
                     b, Unsafe.ARRAY_CHAR_BASE_OFFSET,
                     length, LOG2_ARRAY_CHAR_INDEX_SCALE);

@@ -317,10 +327,12 @@
 
     public static int mismatch(char[] a, int aFromIndex,
                                char[] b, int bFromIndex,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 3) {
             int aOffset = Unsafe.ARRAY_CHAR_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_CHAR_INDEX_SCALE);
             int bOffset = Unsafe.ARRAY_CHAR_BASE_OFFSET + (bFromIndex << LOG2_ARRAY_CHAR_INDEX_SCALE);
             i = vectorizedMismatch(
                     a, aOffset,

@@ -342,10 +354,12 @@
 
     public static int mismatch(short[] a,
                                short[] b,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 3) {
             i = vectorizedMismatch(
                     a, Unsafe.ARRAY_SHORT_BASE_OFFSET,
                     b, Unsafe.ARRAY_SHORT_BASE_OFFSET,
                     length, LOG2_ARRAY_SHORT_INDEX_SCALE);

@@ -362,10 +376,12 @@
 
     public static int mismatch(short[] a, int aFromIndex,
                                short[] b, int bFromIndex,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 3) {
             int aOffset = Unsafe.ARRAY_SHORT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_SHORT_INDEX_SCALE);
             int bOffset = Unsafe.ARRAY_SHORT_BASE_OFFSET + (bFromIndex << LOG2_ARRAY_SHORT_INDEX_SCALE);
             i = vectorizedMismatch(
                     a, aOffset,

@@ -387,10 +403,12 @@
 
     public static int mismatch(int[] a,
                                int[] b,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 1) {
             i = vectorizedMismatch(
                     a, Unsafe.ARRAY_INT_BASE_OFFSET,
                     b, Unsafe.ARRAY_INT_BASE_OFFSET,
                     length, LOG2_ARRAY_INT_INDEX_SCALE);

@@ -407,10 +425,12 @@
 
     public static int mismatch(int[] a, int aFromIndex,
                                int[] b, int bFromIndex,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 1) {
             int aOffset = Unsafe.ARRAY_INT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_INT_INDEX_SCALE);
             int bOffset = Unsafe.ARRAY_INT_BASE_OFFSET + (bFromIndex << LOG2_ARRAY_INT_INDEX_SCALE);
             i = vectorizedMismatch(
                     a, aOffset,

@@ -438,10 +458,12 @@
 
     public static int mismatch(float[] a, int aFromIndex,
                                float[] b, int bFromIndex,
                                int length) {
         int i = 0;
+        if (a[i] != b[i])
+            return i;
         if (length > 1) {
             int aOffset = Unsafe.ARRAY_FLOAT_BASE_OFFSET + (aFromIndex << LOG2_ARRAY_FLOAT_INDEX_SCALE);
             int bOffset = Unsafe.ARRAY_FLOAT_BASE_OFFSET + (bFromIndex << LOG2_ARRAY_FLOAT_INDEX_SCALE);
             i = vectorizedMismatch(
                     a, aOffset,
< prev index next >