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 a2515a93 fix(java): Fix header offset issue in MetaStringBytes 
hashcode (#1668)
a2515a93 is described below

commit a2515a936b439129d93eb22acc5c63a23285f23b
Author: LiangliangSui <116876207+liangliang...@users.noreply.github.com>
AuthorDate: Mon Jun 3 13:07:58 2024 +0800

    fix(java): Fix header offset issue in MetaStringBytes hashcode (#1668)
    
    
    
    ## What does this PR do?
    
    <!-- Describe the purpose of this PR. -->
    MetaStringBytes `hashcode & 0xff`, that is, header, represents the
    encoding
    
    ## Related issues
    
    <!--
    Is there any related issue? Please attach here.
    
    - #xxxx0
    - #xxxx1
    - #xxxx2
    -->
    
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/incubator-fury/issues/new/choose)
    describing the need to do so and update the document if necessary.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    -->
    
    ---------
    
    Signed-off-by: LiangliangSui <coolsui.cod...@gmail.com>
---
 .../src/main/java/org/apache/fury/resolver/MetaStringBytes.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/java/fury-core/src/main/java/org/apache/fury/resolver/MetaStringBytes.java 
b/java/fury-core/src/main/java/org/apache/fury/resolver/MetaStringBytes.java
index 8867a9e7..f14cbce8 100644
--- a/java/fury-core/src/main/java/org/apache/fury/resolver/MetaStringBytes.java
+++ b/java/fury-core/src/main/java/org/apache/fury/resolver/MetaStringBytes.java
@@ -28,6 +28,7 @@ import org.apache.fury.util.MurmurHash3;
 @Internal
 final class MetaStringBytes {
   static final short DEFAULT_DYNAMIC_WRITE_STRING_ID = -1;
+  private static final int HEADER_MASK = 0xff;
 
   final byte[] bytes;
   final long hashCode;
@@ -55,7 +56,7 @@ final class MetaStringBytes {
       hashCode += 256; // last byte is reserved for header.
     }
     hashCode &= 0xffffffffffffff00L;
-    int header = metaString.getEncoding().getValue();
+    int header = metaString.getEncoding().getValue() & HEADER_MASK;
     this.hashCode = hashCode | header;
   }
 
@@ -64,9 +65,8 @@ final class MetaStringBytes {
   }
 
   public String decode(MetaStringDecoder decoder) {
-    int header = (int) (hashCode & 0xff);
-    int encodingFlags = header & 0b111;
-    MetaString.Encoding encoding = MetaString.Encoding.values()[encodingFlags];
+    int header = (int) (hashCode & HEADER_MASK);
+    MetaString.Encoding encoding = MetaString.Encoding.values()[header];
     return decoder.decode(bytes, encoding);
   }
 


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

Reply via email to