You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/04/23 16:00:58 UTC

[GitHub] [ignite-3] ivandasch commented on a change in pull request #105: IGNITE-14407 introduced in-memory vault implementation

ivandasch commented on a change in pull request #105:
URL: https://github.com/apache/ignite-3/pull/105#discussion_r619332749



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
##########
@@ -167,4 +167,63 @@ public static int hash(long key) {
 
         return hash(val);
     }
+
+    /**
+     * Constructs {@code long} from byte array.
+     *
+     * @param bytes Array of bytes.
+     * @param off Offset in {@code bytes} array.
+     * @return Long value.
+     */
+    public static long bytesToLong(byte[] bytes, int off) {

Review comment:
       As for me, this is not a great idea to write this code in java 11
   
   Use this instead
   ```
   static final VarHandle avh = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.BIG_ENDIAN);
   
   byte[] longToBytes(long l) {
   byte[] arr = new byte[8];
   avh.set(arr, 0, context.value);
   return arr;
   }
   
   long bytesToLong(byte[] val, int offset) {
   return (long)avh.get(context.bytesValue, offset / 8 );
   }
   
   ```
   
   This is faster, because of use of intrinsics, and less error prone.




-- 
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.

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