Skip to content

Commit 865e063

Browse files
committed
Use Arrays.equals in ByteArraySequence.equals.
1 parent e255546 commit 865e063

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/io/ByteArraySequence.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -83,8 +83,7 @@ public byte[] toByteArray() {
8383
public boolean equals(Object obj) {
8484
if (this == obj) {
8585
return true;
86-
} else if (obj instanceof ByteArraySequence) {
87-
ByteArraySequence other = ((ByteArraySequence) obj);
86+
} else if (obj instanceof ByteArraySequence other) {
8887
if (buffer == other.buffer) {
8988
return start == other.start && length == other.length;
9089
}
@@ -97,15 +96,10 @@ public boolean equals(Object obj) {
9796
// hash was already computed and hash is not equal
9897
return false;
9998
}
100-
int otherStart = other.start;
101-
for (int i = 0; i < length; i++) {
102-
if (buffer[start + i] != other.buffer[otherStart + i]) {
103-
return false;
104-
}
105-
}
106-
return true;
107-
} else if (obj instanceof ByteSequence) {
108-
ByteSequence other = ((ByteSequence) obj);
99+
return Arrays.equals(
100+
this.buffer, this.start, this.start + this.length,
101+
other.buffer, other.start, other.start + other.length);
102+
} else if (obj instanceof ByteSequence other) {
109103
if (length != other.length()) {
110104
return false;
111105
}

0 commit comments

Comments
 (0)