You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fury.apache.org by ch...@apache.org on 2024/03/28 17:13:05 UTC

(incubator-fury) branch main updated: chore(java): Reuse unsafePutPositiveVarInt in unsafeWritePositiveVarInt (#1434)

This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 7d64ede5 chore(java): Reuse unsafePutPositiveVarInt in unsafeWritePositiveVarInt (#1434)
7d64ede5 is described below

commit 7d64ede53158d648befb3fec18465e96b9d89ca2
Author: LiangliangSui <11...@users.noreply.github.com>
AuthorDate: Fri Mar 29 01:13:01 2024 +0800

    chore(java): Reuse unsafePutPositiveVarInt in unsafeWritePositiveVarInt (#1434)
    
    N/A
    
    Signed-off-by: LiangliangSui <co...@gmail.com>
---
 .../java/org/apache/fury/memory/MemoryBuffer.java  | 46 ++--------------------
 1 file changed, 3 insertions(+), 43 deletions(-)

diff --git a/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java b/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
index 11ca99a9..748aea14 100644
--- a/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
+++ b/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
@@ -1233,49 +1233,9 @@ public final class MemoryBuffer {
    * to avoid using two memory operations.
    */
   public int unsafeWritePositiveVarInt(int v) {
-    // The encoding algorithm are based on kryo UnsafeMemoryOutput.writeVarInt
-    // varint are written using little endian byte order.
-    // This version should have better performance since it remove an index update.
-    long value = v;
-    final int writerIndex = this.writerIndex;
-    long varInt = (value & 0x7F);
-    value >>>= 7;
-    if (value == 0) {
-      UNSAFE.putByte(heapMemory, address + writerIndex, (byte) varInt);
-      this.writerIndex = writerIndex + 1;
-      return 1;
-    }
-    // bit 8 `set` indicates have next data bytes.
-    varInt |= 0x80;
-    varInt |= ((value & 0x7F) << 8);
-    value >>>= 7;
-    if (value == 0) {
-      unsafePutInt(writerIndex, (int) varInt);
-      this.writerIndex = writerIndex + 2;
-      return 2;
-    }
-    varInt |= (0x80 << 8);
-    varInt |= ((value & 0x7F) << 16);
-    value >>>= 7;
-    if (value == 0) {
-      unsafePutInt(writerIndex, (int) varInt);
-      this.writerIndex = writerIndex + 3;
-      return 3;
-    }
-    varInt |= (0x80 << 16);
-    varInt |= ((value & 0x7F) << 24);
-    value >>>= 7;
-    if (value == 0) {
-      unsafePutInt(writerIndex, (int) varInt);
-      this.writerIndex = writerIndex + 4;
-      return 4;
-    }
-    varInt |= (0x80L << 24);
-    varInt |= ((value & 0x7F) << 32);
-    varInt &= 0xFFFFFFFFFL;
-    unsafePutLong(writerIndex, varInt);
-    this.writerIndex = writerIndex + 5;
-    return 5;
+    int varintBytes = unsafePutPositiveVarInt(writerIndex, v);
+    writerIndex += varintBytes;
+    return varintBytes;
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org