Don't fill the array with zeroes when we reinitialize the Throttle with the same number of operations as we already had, as that allows a potentially dangerous burst of operations.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2471 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -73,22 +73,25 @@ public class Throttle
|
|||||||
*/
|
*/
|
||||||
public void reinit (int operations, long period)
|
public void reinit (int operations, long period)
|
||||||
{
|
{
|
||||||
long[] ops = new long[operations];
|
|
||||||
if (operations > _ops.length) {
|
|
||||||
// copy to a larger buffer, leaving zeroes at the beginning
|
|
||||||
int lastOp = _lastOp + operations - _ops.length;
|
|
||||||
System.arraycopy(_ops, 0, ops, 0, _lastOp);
|
|
||||||
System.arraycopy(_ops, _lastOp, ops, lastOp, _ops.length - _lastOp);
|
|
||||||
|
|
||||||
} else if (operations < _ops.length) {
|
|
||||||
// if we're truncating, copy the first (oldest) stamps into ops[0..]
|
|
||||||
int endCount = Math.min(operations, _ops.length - _lastOp);
|
|
||||||
System.arraycopy(_ops, _lastOp, ops, 0, endCount);
|
|
||||||
System.arraycopy(_ops, 0, ops, endCount, operations - endCount);
|
|
||||||
_lastOp = 0;
|
|
||||||
}
|
|
||||||
_ops = ops;
|
|
||||||
_period = period;
|
_period = period;
|
||||||
|
if (operations != _ops.length) {
|
||||||
|
long[] ops = new long[operations];
|
||||||
|
|
||||||
|
if (operations > _ops.length) {
|
||||||
|
// copy to a larger buffer, leaving zeroes at the beginning
|
||||||
|
int lastOp = _lastOp + operations - _ops.length;
|
||||||
|
System.arraycopy(_ops, 0, ops, 0, _lastOp);
|
||||||
|
System.arraycopy(_ops, _lastOp, ops, lastOp, _ops.length - _lastOp);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// if we're truncating, copy the first (oldest) stamps into ops[0..]
|
||||||
|
int endCount = Math.min(operations, _ops.length - _lastOp);
|
||||||
|
System.arraycopy(_ops, _lastOp, ops, 0, endCount);
|
||||||
|
System.arraycopy(_ops, 0, ops, endCount, operations - endCount);
|
||||||
|
_lastOp = 0;
|
||||||
|
}
|
||||||
|
_ops = ops;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user