From ebeab5d351ec5d4f03a56f7bc3cf1e916962b554 Mon Sep 17 00:00:00 2001 From: jiangli Date: Tue, 26 Feb 2019 10:49:48 +0800 Subject: [PATCH] a more elegant way --- .../apache/dubbo/common/timer/HashedWheelTimer.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java index f786caeb8cc..aa39bbe09cd 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java @@ -290,11 +290,13 @@ private static HashedWheelBucket[] createWheel(int ticksPerWheel) { } private static int normalizeTicksPerWheel(int ticksPerWheel) { - int normalizedTicksPerWheel = 1; - while (normalizedTicksPerWheel < ticksPerWheel) { - normalizedTicksPerWheel <<= 1; - } - return normalizedTicksPerWheel; + int normalizedTicksPerWheel = ticksPerWheel - 1; + normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 1; + normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 2; + normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 4; + normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 8; + normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 16; + return normalizedTicksPerWheel + 1; } /**