Skip to content

Commit

Permalink
add custom mismatch() to replace BufferMismatch.mismatch() in ByteBuf…
Browse files Browse the repository at this point in the history
…fer.equals() method
  • Loading branch information
eklaDFF committed Jun 22, 2024
1 parent da0f057 commit 81b303c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/classes/modules/java.base/java/nio/ByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,20 @@ public boolean equals(Object ob) {
int thatRem = that.limit() - thatPos;
if (thisRem < 0 || thisRem != thatRem)
return false;
return BufferMismatch.mismatch(this, thisPos,
return mismatch(this, thisPos,
that, thatPos,
thisRem) < 0;
}

// This method is written to replace BufferMismatch.mismatch(ByteBuffer a, int aOff, ByteBuffer b, int bOff, int length) in equals(Object ob) in this class
private int mismatch(ByteBuffer a, int aOff, ByteBuffer b, int bOff, int length){
for (int i = 0; i < length; i++) {
if (a.get(aOff + i) != b.get(bOff + i))
return i;
}
return -1;
}

Object base() {
return array;
}
Expand Down

0 comments on commit 81b303c

Please sign in to comment.