--- a/src/java.base/share/classes/java/nio/X-Buffer.java.template Wed Dec 20 09:14:06 2017 -0800
+++ b/src/java.base/share/classes/java/nio/X-Buffer.java.template Wed Dec 20 09:14:52 2017 -0800
@@ -36,6 +36,8 @@
import java.util.stream.$Streamtype$Stream;
#end[streamableType]
+import jdk.internal.util.ArraysSupport;
+
/**
* $A$ $type$ buffer.
*
@@ -287,6 +289,11 @@
this(mark, pos, lim, cap, null, 0);
}
+ @Override
+ Object base() {
+ return hb;
+ }
+
#if[byte]
/**
@@ -1297,19 +1304,9 @@
$Type$Buffer that = ($Type$Buffer)ob;
if (this.remaining() != that.remaining())
return false;
- int p = this.position();
- for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--)
- if (!equals(this.get(i), that.get(j)))
- return false;
- return true;
- }
-
- private static boolean equals($type$ x, $type$ y) {
-#if[floatingPointType]
- return (x == y) || ($Fulltype$.isNaN(x) && $Fulltype$.isNaN(y));
-#else[floatingPointType]
- return x == y;
-#end[floatingPointType]
+ return BufferMismatch.mismatch(this, this.position(),
+ that, that.position(),
+ this.remaining()) < 0;
}
/**
@@ -1336,11 +1333,11 @@
* is less than, equal to, or greater than the given buffer
*/
public int compareTo($Type$Buffer that) {
- int n = this.position() + Math.min(this.remaining(), that.remaining());
- for (int i = this.position(), j = that.position(); i < n; i++, j++) {
- int cmp = compare(this.get(i), that.get(j));
- if (cmp != 0)
- return cmp;
+ int i = BufferMismatch.mismatch(this, this.position(),
+ that, that.position(),
+ Math.min(this.remaining(), that.remaining()));
+ if (i >= 0) {
+ return compare(this.get(this.position() + i), that.get(this.position() + i));
}
return this.remaining() - that.remaining();
}
@@ -1571,6 +1568,12 @@
#end[!byte]
+#if[char]
+ // The order or null if the buffer does not cover a memory region,
+ // such as StringCharBuffer
+ abstract ByteOrder charRegionOrder();
+#end[char]
+
#if[byte]
boolean bigEndian // package-private