uschindler commented on a change in pull request #308:
URL: https://github.com/apache/lucene/pull/308#discussion_r711743374



##########
File path: lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java
##########
@@ -81,38 +91,23 @@ public void skipBytes(long count) {
 
   @Override
   public short readShort() {
-    final byte b1 = bytes[pos++];
-    final byte b2 = bytes[pos++];
-    return (short) ((b2 & 0xFF) << 8 | (b1 & 0xFF));
+    final short ret = (short) VH_SHORT.get(bytes, pos);
+    pos += Short.BYTES;
+    return ret;
   }
 
   @Override
   public int readInt() {
-    final byte b1 = bytes[pos++];
-    final byte b2 = bytes[pos++];
-    final byte b3 = bytes[pos++];
-    final byte b4 = bytes[pos++];
-    return (b4 & 0xFF) << 24 | (b3 & 0xFF) << 16 | (b2 & 0xFF) << 8 | (b1 & 
0xFF);
+    final int ret = (int) VH_INT.get(bytes, pos);
+    pos += Integer.BYTES;
+    return ret;
   }
 
   @Override
   public long readLong() {
-    final byte b1 = bytes[pos++];
-    final byte b2 = bytes[pos++];
-    final byte b3 = bytes[pos++];
-    final byte b4 = bytes[pos++];
-    final byte b5 = bytes[pos++];
-    final byte b6 = bytes[pos++];
-    final byte b7 = bytes[pos++];
-    final byte b8 = bytes[pos++];
-    return (b8 & 0xFFL) << 56
-        | (b7 & 0xFFL) << 48
-        | (b6 & 0xFFL) << 40
-        | (b5 & 0xFFL) << 32
-        | (b4 & 0xFFL) << 24
-        | (b3 & 0xFFL) << 16
-        | (b2 & 0xFFL) << 8
-        | (b1 & 0xFFL);
+    final long ret = (long) VH_LONG.get(bytes, pos);

Review comment:
       I had a variant using a finally block previously but reverted that due 
to less readability.
   
   The whole class is documented to not do any bounds checks, so behaviour on 
error does not matter. We may add assertions as suggested in documentation.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to