harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r371957 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio: CharArrayBuffer.java CharBuffer.java CharSequenceAdapter.java CharToByteBufferAdapter.java ReadOnlyCharArrayBuffer.java ReadWriteCharArrayBuffer.java
Date Tue, 24 Jan 2006 17:24:56 GMT
Author: tellison
Date: Tue Jan 24 09:24:50 2006
New Revision: 371957

URL: http://svn.apache.org/viewcvs?rev=371957&view=rev
Log:
Buffer performance enhancements as submitted in HARMONY-43.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java?rev=371957&r1=371956&r2=371957&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
Tue Jan 24 09:24:50 2006
@@ -63,6 +63,18 @@
 		return backingArray[offset + index];
 	}
 
+    public final CharBuffer get(char[] dest, int off, int len) {
+        if ((off < 0 ) || (len < 0) || off + len > dest.length) {
+            throw new IndexOutOfBoundsException();
+        }
+        if (len > remaining()) {
+            throw new BufferUnderflowException();
+        }
+        System.arraycopy(backingArray, offset+position, dest, off, len);
+        position += len;
+        return this;
+    }
+    
 	public final boolean isDirect() {
 		return false;
 	}
@@ -72,12 +84,10 @@
 	}
 
 	public final CharSequence subSequence(int start, int end) {
-		if (start < 0 || start > remaining()) {
-			throw new IndexOutOfBoundsException();
-		}
-		if (end < start || end > remaining()) {
-			throw new IndexOutOfBoundsException();
-		}
+        if (start < 0 || end < start || end > remaining()) {
+            throw new IndexOutOfBoundsException();
+        }
+        
 		CharBuffer result = duplicate();
 		result.limit(position + end);
 		result.position(position + start);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java?rev=371957&r1=371956&r2=371957&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
Tue Jan 24 09:24:50 2006
@@ -91,12 +91,9 @@
 	 *                invalid
 	 */
 	public static CharBuffer wrap(char[] array, int start, int len) {
-		if (start < 0 || start > array.length) {
-			throw new IndexOutOfBoundsException();
-		}
-		if (len < 0 || start + len > array.length) {
-			throw new IndexOutOfBoundsException();
-		}
+        if ((start < 0 ) || (len < 0) || start + len > array.length) {
+            throw new IndexOutOfBoundsException();
+        }
 
 		CharBuffer buf = BufferFactory.newCharBuffer(array);
 		buf.position = start;
@@ -142,12 +139,10 @@
 	 *                invalid
 	 */
 	public static CharBuffer wrap(CharSequence chseq, int start, int end) {
-		if (start < 0 || start > chseq.length()) {
-			throw new IndexOutOfBoundsException();
-		}
-		if (end < start || end > chseq.length()) {
-			throw new IndexOutOfBoundsException();
-		}
+        if (start < 0 || end < start || end > chseq.length()) {
+            throw new IndexOutOfBoundsException();
+        }
+        
 		CharBuffer result = BufferFactory.newCharBuffer(chseq);
 		result.position = start;
 		result.limit = end;
@@ -382,12 +377,10 @@
 	 *                <code>remaining()</code>
 	 */
 	public CharBuffer get(char[] dest, int off, int len) {
-		if (off < 0 || off > dest.length) {
-			throw new IndexOutOfBoundsException();
-		}
-		if ((len < 0) || off + len > dest.length) {
-			throw new IndexOutOfBoundsException();
-		}
+        if ((off < 0 ) || (len < 0) || off + len > dest.length) {
+            throw new IndexOutOfBoundsException();
+        }
+        
 		if (len > remaining()) {
 			throw new BufferUnderflowException();
 		}
@@ -555,12 +548,10 @@
 	 *                If no changes may be made to the contents of this buffer
 	 */
 	public CharBuffer put(char[] src, int off, int len) {
-		if (off < 0 || off > src.length) {
-			throw new IndexOutOfBoundsException();
-		}
-		if (len < 0 || off + len > src.length) {
-			throw new IndexOutOfBoundsException();
-		}
+        if ((off < 0 ) || (len < 0) || off + len > src.length) {
+            throw new IndexOutOfBoundsException();
+        }
+        
 		if (len > remaining()) {
 			throw new BufferOverflowException();
 		}
@@ -593,9 +584,10 @@
 		if (src.remaining() > remaining()) {
 			throw new BufferOverflowException();
 		}
-		while (src.hasRemaining()) {
-			put(src.get());
-		}
+        
+        char[] contents = new char[src.remaining()];
+        src.get(contents);
+        put(contents);
 		return this;
 	}
 
@@ -662,12 +654,10 @@
 	 *                If no changes may be made to the contents of this buffer
 	 */
 	public CharBuffer put(String str, int start, int end) {
-		if (start < 0 || start > str.length()) {
-			throw new IndexOutOfBoundsException();
-		}
-		if (end < start || end > str.length()) {
-			throw new IndexOutOfBoundsException();
-		}
+        if (start < 0 || end < start || end > str.length()) {
+            throw new IndexOutOfBoundsException();
+        }
+        
 		if (end - start > remaining()) {
 			throw new BufferOverflowException();
 		}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java?rev=371957&r1=371956&r2=371957&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
Tue Jan 24 09:24:50 2006
@@ -70,6 +70,19 @@
 		return sequence.charAt(index);
 	}
 
+    public final CharBuffer get(char[] dest, int off, int len) {
+        if ((off < 0 ) || (len < 0) || off + len > dest.length) {
+            throw new IndexOutOfBoundsException();
+        }
+        if (len > remaining()) {
+            throw new BufferUnderflowException();
+        }
+        int newPosition = position + len;
+        sequence.toString().getChars(position, newPosition, dest, off);
+        position = newPosition;
+        return this;
+    }
+
 	public boolean isDirect() {
 		return false;
 	}
@@ -115,12 +128,10 @@
 	}
 
 	public CharSequence subSequence(int start, int end) {
-		if (start < 0 || start > remaining()) {
-			throw new IndexOutOfBoundsException();
-		}
-		if (end < start || end > remaining()) {
-			throw new IndexOutOfBoundsException();
-		}
+        if (end < start || start < 0 || end > remaining()) {
+            throw new IndexOutOfBoundsException();
+        }
+        
 		CharSequenceAdapter result = copy(this);
 		result.position = position + start;
 		result.limit = position + end;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java?rev=371957&r1=371956&r2=371957&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
Tue Jan 24 09:24:50 2006
@@ -139,12 +139,10 @@
 	}
 
 	public CharSequence subSequence(int start, int end) {
-		if (start < 0 || start > remaining()) {
-			throw new IndexOutOfBoundsException();
-		}
-		if (end < start || end > remaining()) {
-			throw new IndexOutOfBoundsException();
-		}
+        if (start < 0 || end < start || end > remaining()) {
+            throw new IndexOutOfBoundsException();
+        }
+        
 		CharBuffer result = duplicate();
 		result.limit(position + end);
 		result.position(position + start);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java?rev=371957&r1=371956&r2=371957&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
Tue Jan 24 09:24:50 2006
@@ -80,6 +80,14 @@
 		throw new ReadOnlyBufferException();
 	}
 
+    public final CharBuffer put(char[] src, int off, int len) {
+        throw new ReadOnlyBufferException();
+    }
+
+    public CharBuffer put(String src, int start, int end) {
+        throw new ReadOnlyBufferException();
+    }
+
 	public CharBuffer slice() {
 		return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset
 				+ position);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java?rev=371957&r1=371956&r2=371957&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
Tue Jan 24 09:24:50 2006
@@ -100,6 +100,18 @@
 		return this;
 	}
 
+    public CharBuffer put(char[] src, int off, int len) {
+        if (off < 0 || len < 0 || len + off > src.length) {
+            throw new IndexOutOfBoundsException();
+        }
+        if (len > remaining()) {
+            throw new BufferOverflowException();
+        }
+        System.arraycopy(src, off, backingArray, offset+position, len);
+        position += len;
+        return this;
+    }
+    
 	public CharBuffer slice() {
 		return new ReadWriteCharArrayBuffer(remaining(), backingArray, offset
 				+ position);



Mime
View raw message