commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives ArrayCharList.java ArrayFloatList.java ArrayByteList.java ArrayShortList.java ArrayBooleanList.java ArrayIntList.java ArrayLongList.java ArrayDoubleList.java
Date Mon, 03 Jan 2005 23:20:42 GMT
scolebourne    2005/01/03 15:20:42

  Modified:    primitives/src/java/org/apache/commons/collections/primitives
                        ArrayCharList.java ArrayFloatList.java
                        ArrayByteList.java ArrayShortList.java
                        ArrayBooleanList.java ArrayIntList.java
                        ArrayLongList.java ArrayDoubleList.java
  Log:
  Improve performance of addAll
  bug 30604, from Robert Fischer
  
  Revision  Changes    Path
  1.6       +26 -2     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayCharList.java
  
  Index: ArrayCharList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayCharList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArrayCharList.java	25 Feb 2004 20:46:25 -0000	1.5
  +++ ArrayCharList.java	3 Jan 2005 23:20:42 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -155,6 +155,30 @@
       public void clear() {
           incrModCount();
           _size = 0;
  +    }
  +
  +    public boolean addAll(CharCollection collection) {
  +        return addAll(size(), collection);
  +    }
  +
  +    public boolean addAll(int index, CharCollection collection) {
  +        if (collection.size() == 0) {
  +            return false;
  +        }
  +        checkRangeIncludingEndpoint(index);
  +        incrModCount();
  +        ensureCapacity(_size + collection.size());
  +        if (index != _size) {
  +            // Need to move some elements
  +            System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +        }
  +        int ptr = index;
  +        for (CharIterator it = collection.iterator(); it.hasNext();) {
  +            _data[index] = it.next();
  +            index++;
  +        }
  +        _size += collection.size();
  +        return true;
       }
   
       // capacity methods
  
  
  
  1.6       +26 -2     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayFloatList.java
  
  Index: ArrayFloatList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayFloatList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArrayFloatList.java	25 Feb 2004 20:46:25 -0000	1.5
  +++ ArrayFloatList.java	3 Jan 2005 23:20:42 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -155,6 +155,30 @@
       public void clear() {
           incrModCount();
           _size = 0;
  +    }
  +
  +    public boolean addAll(FloatCollection collection) {
  +        return addAll(size(), collection);
  +    }
  +
  +    public boolean addAll(int index, FloatCollection collection) {
  +        if (collection.size() == 0) {
  +            return false;
  +        }
  +        checkRangeIncludingEndpoint(index);
  +        incrModCount();
  +        ensureCapacity(_size + collection.size());
  +        if (index != _size) {
  +            // Need to move some elements
  +            System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +        }
  +        int ptr = index;
  +        for (FloatIterator it = collection.iterator(); it.hasNext();) {
  +            _data[index] = it.next();
  +            index++;
  +        }
  +        _size += collection.size();
  +        return true;
       }
   
       // capacity methods
  
  
  
  1.6       +26 -2     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayByteList.java
  
  Index: ArrayByteList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayByteList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArrayByteList.java	25 Feb 2004 20:46:25 -0000	1.5
  +++ ArrayByteList.java	3 Jan 2005 23:20:42 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -157,6 +157,30 @@
           _size = 0;
       }
       
  +    public boolean addAll(ByteCollection collection) {
  +        return addAll(size(), collection);
  +    }
  +
  +    public boolean addAll(int index, ByteCollection collection) {
  +        if (collection.size() == 0) {
  +            return false;
  +        }
  +        checkRangeIncludingEndpoint(index);
  +        incrModCount();
  +        ensureCapacity(_size + collection.size());
  +        if (index != _size) {
  +            // Need to move some elements
  +            System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +        }
  +        int ptr = index;
  +        for (ByteIterator it = collection.iterator(); it.hasNext();) {
  +            _data[index] = it.next();
  +            index++;
  +        }
  +        _size += collection.size();
  +        return true;
  +    }
  +
       // capacity methods
       //-------------------------------------------------------------------------
   
  
  
  
  1.6       +26 -2     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayShortList.java
  
  Index: ArrayShortList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayShortList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArrayShortList.java	25 Feb 2004 20:46:25 -0000	1.5
  +++ ArrayShortList.java	3 Jan 2005 23:20:42 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -155,6 +155,30 @@
       public void clear() {
           incrModCount();
           _size = 0;
  +    }
  +
  +    public boolean addAll(ShortCollection collection) {
  +        return addAll(size(), collection);
  +    }
  +
  +    public boolean addAll(int index, ShortCollection collection) {
  +        if (collection.size() == 0) {
  +            return false;
  +        }
  +        checkRangeIncludingEndpoint(index);
  +        incrModCount();
  +        ensureCapacity(_size + collection.size());
  +        if (index != _size) {
  +            // Need to move some elements
  +            System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +        }
  +        int ptr = index;
  +        for (ShortIterator it = collection.iterator(); it.hasNext();) {
  +            _data[index] = it.next();
  +            index++;
  +        }
  +        _size += collection.size();
  +        return true;
       }
   
       // capacity methods
  
  
  
  1.4       +26 -2     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayBooleanList.java
  
  Index: ArrayBooleanList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayBooleanList.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ArrayBooleanList.java	12 Jul 2004 18:29:44 -0000	1.3
  +++ ArrayBooleanList.java	3 Jan 2005 23:20:42 -0000	1.4
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -154,6 +154,30 @@
           _size = 0;
       }
       
  +    public boolean addAll(BooleanCollection collection) {
  +        return addAll(size(), collection);
  +    }
  +
  +    public boolean addAll(int index, BooleanCollection collection) {
  +        if (collection.size() == 0) {
  +            return false;
  +        }
  +        checkRangeIncludingEndpoint(index);
  +        incrModCount();
  +        ensureCapacity(_size + collection.size());
  +        if (index != _size) {
  +            // Need to move some elements
  +            System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +        }
  +        int ptr = index;
  +        for (BooleanIterator it = collection.iterator(); it.hasNext();) {
  +            _data[index] = it.next();
  +            index++;
  +        }
  +        _size += collection.size();
  +        return true;
  +    }
  +
       // capacity methods
       //-------------------------------------------------------------------------
   
  
  
  
  1.6       +28 -3     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayIntList.java
  
  Index: ArrayIntList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayIntList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArrayIntList.java	25 Feb 2004 20:46:25 -0000	1.5
  +++ ArrayIntList.java	3 Jan 2005 23:20:42 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -27,7 +27,8 @@
    * @since Commons Primitives 1.0
    * @version $Revision$ $Date$
    * 
  - * @author Rodney Waldhoff 
  + * @author Rodney Waldhoff
  + * @author Robert Fischer
    */
   public class ArrayIntList extends RandomAccessIntList implements IntList, Serializable
{
   
  @@ -156,6 +157,30 @@
           incrModCount();
           _size = 0;
       }
  +
  +    public boolean addAll(IntCollection collection) {
  +		return addAll(size(), collection);
  +	}
  +
  +	public boolean addAll(int index, IntCollection collection) {
  +		if (collection.size() == 0) {
  +			return false;
  +        }
  +		checkRangeIncludingEndpoint(index);
  +		incrModCount();
  +		ensureCapacity(_size + collection.size());
  +		if (index != _size) {
  +			// Need to move some elements
  +			System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +		}
  +		int ptr = index;
  +		for (IntIterator it = collection.iterator(); it.hasNext();) {
  +			_data[index] = it.next();
  +			index++;
  +		}
  +		_size += collection.size();
  +		return true;
  +	}
   
       // capacity methods
       //-------------------------------------------------------------------------
  
  
  
  1.6       +26 -2     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayLongList.java
  
  Index: ArrayLongList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayLongList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArrayLongList.java	25 Feb 2004 20:46:25 -0000	1.5
  +++ ArrayLongList.java	3 Jan 2005 23:20:42 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -155,6 +155,30 @@
       public void clear() {
           incrModCount();
           _size = 0;
  +    }
  +
  +    public boolean addAll(LongCollection collection) {
  +        return addAll(size(), collection);
  +    }
  +
  +    public boolean addAll(int index, LongCollection collection) {
  +        if (collection.size() == 0) {
  +            return false;
  +        }
  +        checkRangeIncludingEndpoint(index);
  +        incrModCount();
  +        ensureCapacity(_size + collection.size());
  +        if (index != _size) {
  +            // Need to move some elements
  +            System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +        }
  +        int ptr = index;
  +        for (LongIterator it = collection.iterator(); it.hasNext();) {
  +            _data[index] = it.next();
  +            index++;
  +        }
  +        _size += collection.size();
  +        return true;
       }
   
       // capacity methods
  
  
  
  1.6       +26 -2     jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayDoubleList.java
  
  Index: ArrayDoubleList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/ArrayDoubleList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArrayDoubleList.java	25 Feb 2004 20:46:25 -0000	1.5
  +++ ArrayDoubleList.java	3 Jan 2005 23:20:42 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2005 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -155,6 +155,30 @@
       public void clear() {
           incrModCount();
           _size = 0;
  +    }
  +
  +    public boolean addAll(DoubleCollection collection) {
  +        return addAll(size(), collection);
  +    }
  +
  +    public boolean addAll(int index, DoubleCollection collection) {
  +        if (collection.size() == 0) {
  +            return false;
  +        }
  +        checkRangeIncludingEndpoint(index);
  +        incrModCount();
  +        ensureCapacity(_size + collection.size());
  +        if (index != _size) {
  +            // Need to move some elements
  +            System.arraycopy(_data, index, _data, index + collection.size(), _size - index);
  +        }
  +        int ptr = index;
  +        for (DoubleIterator it = collection.iterator(); it.hasNext();) {
  +            _data[index] = it.next();
  +            index++;
  +        }
  +        _size += collection.size();
  +        return true;
       }
   
       // capacity methods
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message