ActionFrequency.update: reorder safety checks slightly.

Gains a little bit of consistency for negative time differences. Also
might be faster for the case of seldom shifting, though most likely
by an insignificant amount.
This commit is contained in:
asofold 2013-01-13 22:11:29 +01:00
parent 363cda50e8
commit f0e9a844fc

View File

@ -50,16 +50,16 @@ public class ActionFrequency {
*/
public final void update(final long now) {
final long diff = now - time;
final int shift = (int) ((float) diff / (float) durBucket);
if (shift == 0){
// No update.
if (diff < durBucket){
// No update (first bucket).
return;
}
else if (shift >= buckets.length || shift < 0){
else if (diff >= durBucket * buckets.length || diff < 0){
// Clear (beyond range).
clear(now);
return;
}
final int shift = (int) ((float) diff / (float) durBucket);
// Update buckets.
for (int i = 0; i < buckets.length - shift; i++){
buckets[buckets.length - (i + 1)] = buckets[buckets.length - (i + 1 + shift)];