diff --git a/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/TimerWheelBenchmark.java b/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/TimerWheelBenchmark.java index e0dc2b8ed4..9719800a69 100644 --- a/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/TimerWheelBenchmark.java +++ b/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/TimerWheelBenchmark.java @@ -80,6 +80,11 @@ public void expire(ThreadState threadState) { timerWheel.schedule(timer); } + @Benchmark + public long getExpirationDelay() { + return timerWheel.getExpirationDelay(); + } + static final class Timer extends Node { Node prev; Node next; diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java index 5c0d09b6dc..5fd35d4289 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java @@ -234,6 +234,7 @@ void unlink(Node node) { } /** Returns the duration until the next bucket expires, or {@link Long.MAX_VALUE} if none. */ + @SuppressWarnings("IntLongMath") public long getExpirationDelay() { for (int i = 0; i < SHIFT.length; i++) { Node[] timerWheel = wheel[i]; @@ -247,7 +248,8 @@ public long getExpirationDelay() { Node sentinel = timerWheel[(j & mask)]; Node next = sentinel.getNextInVariableOrder(); if (sentinel != next) { - long delay = ((j - start) * SPANS[i]) - (nanos & spanMask); + long buckets = (j - start); + long delay = (buckets << SHIFT[i]) - (nanos & spanMask); return (delay > 0) ? delay : SPANS[i]; } }