Skip to content

Commit b149378

Browse files
CalvinKirscarryxyh
authored andcommitted
a more elegant way (#3567)
1 parent 5434ab7 commit b149378

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,13 @@ private static HashedWheelBucket[] createWheel(int ticksPerWheel) {
290290
}
291291

292292
private static int normalizeTicksPerWheel(int ticksPerWheel) {
293-
int normalizedTicksPerWheel = 1;
294-
while (normalizedTicksPerWheel < ticksPerWheel) {
295-
normalizedTicksPerWheel <<= 1;
296-
}
297-
return normalizedTicksPerWheel;
293+
int normalizedTicksPerWheel = ticksPerWheel - 1;
294+
normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 1;
295+
normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 2;
296+
normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 4;
297+
normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 8;
298+
normalizedTicksPerWheel |= normalizedTicksPerWheel >>> 16;
299+
return normalizedTicksPerWheel + 1;
298300
}
299301

300302
/**

0 commit comments

Comments
 (0)