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

srowen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new b12c12790c7 [SPARK-39282][SQL] Replace If-Else branch with bitwise 
operators in roundNumberOfBytesToNearestWord
b12c12790c7 is described below

commit b12c12790c7c4453c1f9e62d49feba30957c0af3
Author: zhixingheyi-tian <xiangxiang.s...@intel.com>
AuthorDate: Sat May 28 14:15:59 2022 -0500

    [SPARK-39282][SQL] Replace If-Else branch with bitwise operators in 
roundNumberOfBytesToNearestWord
    
    ### What changes were proposed in this pull request?
    
    Use bitwise operators to avoid If-Else branch and improve computation 
performance.
    
    ### How was this patch tested?
     Existed UTs.
    
    Closes #36659 from zhixingheyi-tian/avoid_ifelse_branch.
    
    Authored-by: zhixingheyi-tian <xiangxiang.s...@intel.com>
    Signed-off-by: Sean Owen <sro...@gmail.com>
---
 .../main/java/org/apache/spark/unsafe/array/ByteArrayMethods.java   | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git 
a/common/unsafe/src/main/java/org/apache/spark/unsafe/array/ByteArrayMethods.java
 
b/common/unsafe/src/main/java/org/apache/spark/unsafe/array/ByteArrayMethods.java
index deb7d2bf1b0..500bc9de325 100644
--- 
a/common/unsafe/src/main/java/org/apache/spark/unsafe/array/ByteArrayMethods.java
+++ 
b/common/unsafe/src/main/java/org/apache/spark/unsafe/array/ByteArrayMethods.java
@@ -39,11 +39,7 @@ public class ByteArrayMethods {
 
   public static long roundNumberOfBytesToNearestWord(long numBytes) {
     long remainder = numBytes & 0x07;  // This is equivalent to `numBytes % 8`
-    if (remainder == 0) {
-      return numBytes;
-    } else {
-      return numBytes + (8 - remainder);
-    }
+    return numBytes + ((8 - remainder) & 0x7);
   }
 
   // Some JVMs can't allocate arrays of length Integer.MAX_VALUE; actual max 
is somewhat smaller.


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

Reply via email to