Optimise the remove implementation for performance of common case

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131840 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2005-01-22 00:48:22 +00:00
parent 46d73eac81
commit 1da9c06f4d
1 changed files with 16 additions and 10 deletions

View File

@ -53,7 +53,7 @@ import org.apache.commons.collections.BufferUnderflowException;
* This class is Serializable from Commons Collections 3.1. * This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 (previously in main package v2.1) * @since Commons Collections 3.0 (previously in main package v2.1)
* @version $Revision: 1.10 $ $Date: 2005/01/15 22:47:40 $ * @version $Revision: 1.11 $ $Date: 2005/01/22 00:48:22 $
* *
* @author Avalon * @author Avalon
* @author Berin Loritsch * @author Berin Loritsch
@ -355,15 +355,21 @@ public class BoundedFifoBuffer extends AbstractCollection
return; return;
} }
// Other elements require us to shift the subsequent elements int pos = lastReturnedIndex + 1;
int i = lastReturnedIndex + 1; if (start < lastReturnedIndex && pos < end) {
while (i != end) { // shift in one part
if (i >= maxElements) { System.arraycopy(elements, pos, elements,
elements[i - 1] = elements[0]; lastReturnedIndex, end - pos);
i = 0; } else {
} else { // Other elements require us to shift the subsequent elements
elements[decrement(i)] = elements[i]; while (pos != end) {
i = increment(i); if (pos >= maxElements) {
elements[pos - 1] = elements[0];
pos = 0;
} else {
elements[decrement(pos)] = elements[pos];
pos = increment(pos);
}
} }
} }