You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/09/19 13:03:08 UTC

[GitHub] [lucene] dweiss commented on a change in pull request #308: LUCENE-10113: Use VarHandles to access int/long/short types in ByteArrayDataInput

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



##########
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:
       This introduces a subtle change: the input's position is not moved the same way as before in case the AIOOB is thrown somewhere along the way. I'm not sure if this matters... but perhaps if the array is exhausted the pos should be moved (so that it points past the end of the array) instead of keeping it at the previous position? 




-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org