Skip to content

Commit

Permalink
a more elegant way (#3567)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKirs authored and carryxyh committed Feb 26, 2019
1 parent 5434ab7 commit b149378
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit b149378

Please sign in to comment.