From 1da9c06f4dbcbeb69f01ca24d9a87094312701e7 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 22 Jan 2005 00:48:22 +0000 Subject: [PATCH] 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 --- .../collections/buffer/BoundedFifoBuffer.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java b/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java index 8277e97f4..44ce20b46 100644 --- a/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java +++ b/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java @@ -53,7 +53,7 @@ import org.apache.commons.collections.BufferUnderflowException; * This class is Serializable from Commons Collections 3.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 Berin Loritsch @@ -355,15 +355,21 @@ public class BoundedFifoBuffer extends AbstractCollection return; } - // Other elements require us to shift the subsequent elements - int i = lastReturnedIndex + 1; - while (i != end) { - if (i >= maxElements) { - elements[i - 1] = elements[0]; - i = 0; - } else { - elements[decrement(i)] = elements[i]; - i = increment(i); + int pos = lastReturnedIndex + 1; + if (start < lastReturnedIndex && pos < end) { + // shift in one part + System.arraycopy(elements, pos, elements, + lastReturnedIndex, end - pos); + } else { + // Other elements require us to shift the subsequent elements + while (pos != end) { + if (pos >= maxElements) { + elements[pos - 1] = elements[0]; + pos = 0; + } else { + elements[decrement(pos)] = elements[pos]; + pos = increment(pos); + } } }