Skip to content

Commit 77e53f9

Browse files
committed
Small cleanups
1 parent 3f4f5c4 commit 77e53f9

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/main/java/org/truffleruby/core/string/TBytesKey.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,8 @@ private static int hashCode(InternalByteArray byteArray) {
9696
return hashCode(byteArray.getArray(), byteArray.getOffset(), byteArray.getLength());
9797
}
9898

99-
// A variant of <code>Arrays.hashCode</code> that allows for selecting a range within the array.
99+
/** A variant of {@link Arrays#hashCode(byte[])} that allows for selecting a range within the array. */
100100
private static int hashCode(byte[] bytes, int offset, int length) {
101-
if (bytes == null) {
102-
return 0;
103-
}
104-
105101
int result = 1;
106102
for (int i = offset; i < offset + length; i++) {
107103
result = 31 * result + bytes[i];
@@ -124,7 +120,7 @@ private boolean isPerfectFit() {
124120
* cache hit. To avoid incurring that cost unnecessarily, we allow cache keys to refer to a subset of a byte array.
125121
* While that saves computation during a cache lookup, it means such keys are unsuitable for insertion into the
126122
* cache. This method makes a key we can use safely for insertion.
127-
*
123+
* <p>
128124
* If we know that the key refers to an immutable byte array and the key does not refer to a substring, we can
129125
* safely refer to the original byte array without needing to make an additional copy.
130126
*
@@ -135,7 +131,7 @@ public TBytesKey makeCacheable(boolean isImmutable) {
135131
return this;
136132
}
137133

138-
// Make a copy of the substring's bytes so we can cache them without retaining the original byte array.
134+
// Make a copy of the substring's bytes so we can cache them without retaining the larger original byte array.
139135
var resolvedSubstring = ArrayUtils.extractRange(this.bytes, this.offset, this.offset + this.length);
140136

141137
return new TBytesKey(resolvedSubstring, encoding);

0 commit comments

Comments
 (0)