From ac8700f8a6e1ecce71cb3e0ff91ecffd77824292 Mon Sep 17 00:00:00 2001 From: Prototik Date: Fri, 14 Aug 2015 03:15:53 +0700 Subject: [PATCH] Reduce calls of System.currentTimeMillis() in TickLimiter, close #130 --- src/main/java/kcauldron/KCauldron.java | 1 + src/main/java/org/spigotmc/TickLimiter.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/kcauldron/KCauldron.java b/src/main/java/kcauldron/KCauldron.java index eb86a1b..c6bf1bb 100644 --- a/src/main/java/kcauldron/KCauldron.java +++ b/src/main/java/kcauldron/KCauldron.java @@ -111,6 +111,7 @@ public class KCauldron { public static int lookupForgeRevision() { if (sForgeRevision != 0) return sForgeRevision; int revision = Integer.parseInt(System.getProperty("kcauldron.forgeRevision", "0")); + if (revision != 0) return sForgeRevision = revision; try { Properties p = new Properties(); p.load(KCauldron.class diff --git a/src/main/java/org/spigotmc/TickLimiter.java b/src/main/java/org/spigotmc/TickLimiter.java index 74ac1fb..9b5f6a0 100644 --- a/src/main/java/org/spigotmc/TickLimiter.java +++ b/src/main/java/org/spigotmc/TickLimiter.java @@ -3,16 +3,23 @@ package org.spigotmc; public class TickLimiter { private final int maxTime; private long startTime; - + private int tick; + private boolean shouldContinue; public TickLimiter(int maxTime) { this.maxTime = maxTime; } public void initTick() { startTime = System.currentTimeMillis(); + tick = 0; + shouldContinue = true; } public boolean shouldContinue() { - return System.currentTimeMillis() - startTime < maxTime; + if (++tick >= 300 && !shouldContinue) { + tick = 0; + shouldContinue = System.currentTimeMillis() - startTime < maxTime; + } + return shouldContinue; } }