From f2817f3c8f3bff8f890c8c0f771bf58942b25cc0 Mon Sep 17 00:00:00 2001 From: ZelvaLea Date: Wed, 12 Apr 2023 19:39:23 +0300 Subject: [PATCH 1/2] micro optimization --- src/main/java/com/mojang/datafixers/DataFixUtils.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mojang/datafixers/DataFixUtils.java b/src/main/java/com/mojang/datafixers/DataFixUtils.java index cf8959ae..db4b41f3 100644 --- a/src/main/java/com/mojang/datafixers/DataFixUtils.java +++ b/src/main/java/com/mojang/datafixers/DataFixUtils.java @@ -14,13 +14,8 @@ private DataFixUtils() { // Based on: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 public static int smallestEncompassingPowerOfTwo(final int input) { - int result = input - 1; - result |= result >> 1; - result |= result >> 2; - result |= result >> 4; - result |= result >> 8; - result |= result >> 16; - return result + 1; + int n = -1 >>> Integer.numberOfLeadingZeros(input - 1); + return n + 1; } // Based on: http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 From 3885df14c73c395336b7327bd217f7f1edfd4c69 Mon Sep 17 00:00:00 2001 From: sunmisc Date: Sun, 30 Mar 2025 01:57:51 +0300 Subject: [PATCH 2/2] reformat into one line --- src/main/java/com/mojang/datafixers/DataFixUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/mojang/datafixers/DataFixUtils.java b/src/main/java/com/mojang/datafixers/DataFixUtils.java index db4b41f3..fb2fbccb 100644 --- a/src/main/java/com/mojang/datafixers/DataFixUtils.java +++ b/src/main/java/com/mojang/datafixers/DataFixUtils.java @@ -14,8 +14,7 @@ private DataFixUtils() { // Based on: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 public static int smallestEncompassingPowerOfTwo(final int input) { - int n = -1 >>> Integer.numberOfLeadingZeros(input - 1); - return n + 1; + return (-1 >>> Integer.numberOfLeadingZeros(input - 1)) + 1; } // Based on: http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2