# HG changeset patch # User Jaroslav Tulach # Date 1358978128 -3600 # Node ID 53fafe3848039ac4e28871cc43ae08a08e947f25 # Parent df92e9608039a402a083a448d0935bcaf566e44f Moving all arraycopy methods into one System class diff -r df92e9608039 -r 53fafe384803 emul/compact/src/main/java/java/io/BufferedReader.java --- a/emul/compact/src/main/java/java/io/BufferedReader.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/compact/src/main/java/java/io/BufferedReader.java Wed Jan 23 22:55:28 2013 +0100 @@ -25,6 +25,8 @@ package java.io; +import org.apidesign.bck2brwsr.emul.lang.System; + /** * Reads text from a character-input stream, buffering characters so as to diff -r df92e9608039 -r 53fafe384803 emul/compact/src/main/java/java/io/InputStreamReader.java --- a/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 22:55:28 2013 +0100 @@ -109,13 +109,14 @@ * @since 1.4 * @spec JSR-51 */ +/* XXX: public InputStreamReader(InputStream in, Charset cs) { super(in); if (cs == null) throw new NullPointerException("charset"); sd = StreamDecoder.forInputStreamReader(in, this, cs); } - +*/ /** * Creates an InputStreamReader that uses the given charset decoder.

* @@ -125,13 +126,15 @@ * @since 1.4 * @spec JSR-51 */ +/* XXX: public InputStreamReader(InputStream in, CharsetDecoder dec) { super(in); if (dec == null) throw new NullPointerException("charset decoder"); sd = StreamDecoder.forInputStreamReader(in, this, dec); } - +*/ + /** * Returns the name of the character encoding being used by this stream. * diff -r df92e9608039 -r 53fafe384803 emul/compact/src/main/java/java/io/Reader.java --- a/emul/compact/src/main/java/java/io/Reader.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/compact/src/main/java/java/io/Reader.java Wed Jan 23 22:55:28 2013 +0100 @@ -94,14 +94,14 @@ * @throws ReadOnlyBufferException if target is a read only buffer * @since 1.5 */ - public int read(java.nio.CharBuffer target) throws IOException { - int len = target.remaining(); - char[] cbuf = new char[len]; - int n = read(cbuf, 0, len); - if (n > 0) - target.put(cbuf, 0, n); - return n; - } +// public int read(java.nio.CharBuffer target) throws IOException { +// int len = target.remaining(); +// char[] cbuf = new char[len]; +// int n = read(cbuf, 0, len); +// if (n > 0) +// target.put(cbuf, 0, n); +// return n; +// } /** * Reads a single character. This method will block until a character is diff -r df92e9608039 -r 53fafe384803 emul/compact/src/main/java/java/lang/Readable.java --- a/emul/compact/src/main/java/java/lang/Readable.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/compact/src/main/java/java/lang/Readable.java Wed Jan 23 22:55:28 2013 +0100 @@ -50,6 +50,6 @@ * @throws NullPointerException if cb is null * @throws java.nio.ReadOnlyBufferException if cb is a read only buffer */ - public int read(java.nio.CharBuffer cb) throws IOException; +// XXX: public int read(java.nio.CharBuffer cb) throws IOException; } diff -r df92e9608039 -r 53fafe384803 emul/compact/src/main/java/java/util/ArrayList.java --- a/emul/compact/src/main/java/java/util/ArrayList.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/compact/src/main/java/java/util/ArrayList.java Wed Jan 23 22:55:28 2013 +0100 @@ -25,6 +25,8 @@ package java.util; +import org.apidesign.bck2brwsr.emul.lang.System; + /** * Resizable-array implementation of the List interface. Implements * all optional list operations, and permits all elements, including @@ -689,51 +691,6 @@ } /** - * Save the state of the ArrayList instance to a stream (that - * is, serialize it). - * - * @serialData The length of the array backing the ArrayList - * instance is emitted (int), followed by all of its elements - * (each an Object) in the proper order. - */ - private void writeObject(java.io.ObjectOutputStream s) - throws java.io.IOException{ - // Write out element count, and any hidden stuff - int expectedModCount = modCount; - s.defaultWriteObject(); - - // Write out array length - s.writeInt(elementData.length); - - // Write out all elements in the proper order. - for (int i=0; iArrayList instance from a stream (that is, - * deserialize it). - */ - private void readObject(java.io.ObjectInputStream s) - throws java.io.IOException, ClassNotFoundException { - // Read in size, and any hidden stuff - s.defaultReadObject(); - - // Read in array length and allocate array - int arrayLength = s.readInt(); - Object[] a = elementData = new Object[arrayLength]; - - // Read in all elements in the proper order. - for (int i=0; iHashMap instance to a stream (i.e., - * serialize it). - * - * @serialData The capacity of the HashMap (the length of the - * bucket array) is emitted (int), followed by the - * size (an int, the number of key-value - * mappings), followed by the key (Object) and value (Object) - * for each key-value mapping. The key-value mappings are - * emitted in no particular order. - */ - private void writeObject(java.io.ObjectOutputStream s) - throws IOException - { - Iterator> i = - (size > 0) ? entrySet0().iterator() : null; - - // Write out the threshold, loadfactor, and any hidden stuff - s.defaultWriteObject(); - - // Write out number of buckets - s.writeInt(table.length); - - // Write out size (number of Mappings) - s.writeInt(size); - - // Write out keys and values (alternating) - if (i != null) { - while (i.hasNext()) { - Map.Entry e = i.next(); - s.writeObject(e.getKey()); - s.writeObject(e.getValue()); - } - } - } private static final long serialVersionUID = 362498820763181265L; - /** - * Reconstitute the HashMap instance from a stream (i.e., - * deserialize it). - */ - private void readObject(java.io.ObjectInputStream s) - throws IOException, ClassNotFoundException - { - // Read in the threshold, loadfactor, and any hidden stuff - s.defaultReadObject(); - - // Read in number of buckets and allocate the bucket array; - int numBuckets = s.readInt(); - table = new Entry[numBuckets]; - - init(); // Give subclass a chance to do its thing. - - // Read in size (number of Mappings) - int size = s.readInt(); - - // Read the keys and values, and put the mappings in the HashMap - for (int i=0; iHashSet instance to a stream (that is, - * serialize it). - * - * @serialData The capacity of the backing HashMap instance - * (int), and its load factor (float) are emitted, followed by - * the size of the set (the number of elements it contains) - * (int), followed by all of its elements (each an Object) in - * no particular order. - */ - private void writeObject(java.io.ObjectOutputStream s) - throws java.io.IOException { - // Write out any hidden serialization magic - s.defaultWriteObject(); - - // Write out HashMap capacity and load factor - s.writeInt(map.capacity()); - s.writeFloat(map.loadFactor()); - - // Write out size - s.writeInt(map.size()); - - // Write out all elements in the proper order. - for (E e : map.keySet()) - s.writeObject(e); - } - - /** - * Reconstitute the HashSet instance from a stream (that is, - * deserialize it). - */ - private void readObject(java.io.ObjectInputStream s) - throws java.io.IOException, ClassNotFoundException { - // Read in any hidden serialization magic - s.defaultReadObject(); - - // Read in HashMap capacity and load factor and create backing HashMap - int capacity = s.readInt(); - float loadFactor = s.readFloat(); - map = (((HashSet)this) instanceof LinkedHashSet ? - new LinkedHashMap(capacity, loadFactor) : - new HashMap(capacity, loadFactor)); - - // Read in size - int size = s.readInt(); - - // Read in all elements in the proper order. - for (int i=0; iByteArrayInputStream contains * an internal buffer that contains bytes that @@ -191,7 +193,7 @@ if (len <= 0) { return 0; } - PushbackInputStream.arraycopy(buf, pos, b, off, len); + System.arraycopy(buf, pos, b, off, len); pos += len; return len; } diff -r df92e9608039 -r 53fafe384803 emul/mini/src/main/java/java/io/DataInputStream.java --- a/emul/mini/src/main/java/java/io/DataInputStream.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/mini/src/main/java/java/io/DataInputStream.java Wed Jan 23 22:55:28 2013 +0100 @@ -26,6 +26,7 @@ package java.io; import org.apidesign.bck2brwsr.core.JavaScriptBody; +import org.apidesign.bck2brwsr.emul.lang.System; /** * A data input stream lets an application read primitive Java data @@ -565,7 +566,7 @@ if (--room < 0) { buf = new char[offset + 128]; room = buf.length - offset - 1; - arraycopy(lineBuffer, 0, buf, 0, offset); + System.arraycopy(lineBuffer, 0, buf, 0, offset); lineBuffer = buf; } buf[offset++] = (char) c; @@ -696,9 +697,4 @@ // The number of chars produced may be less than utflen return new String(chararr, 0, chararr_count); } - static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) { - while (count-- > 0) { - dst[dstBegin++] = value[srcBegin++]; - } - } } diff -r df92e9608039 -r 53fafe384803 emul/mini/src/main/java/java/io/PushbackInputStream.java --- a/emul/mini/src/main/java/java/io/PushbackInputStream.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/mini/src/main/java/java/io/PushbackInputStream.java Wed Jan 23 22:55:28 2013 +0100 @@ -25,6 +25,8 @@ package java.io; +import org.apidesign.bck2brwsr.emul.lang.System; + /** * A PushbackInputStream adds * functionality to another input stream, namely @@ -177,7 +179,7 @@ if (len < avail) { avail = len; } - arraycopy(buf, pos, b, off, avail); + System.arraycopy(buf, pos, b, off, avail); pos += avail; off += avail; len -= avail; @@ -232,7 +234,7 @@ throw new IOException("Push back buffer is full"); } pos -= len; - arraycopy(b, off, buf, pos, len); + System.arraycopy(b, off, buf, pos, len); } /** @@ -380,9 +382,4 @@ in = null; buf = null; } - static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) { - while (count-- > 0) { - dst[dstBegin++] = value[srcBegin++]; - } - } } diff -r df92e9608039 -r 53fafe384803 emul/mini/src/main/java/java/lang/AbstractStringBuilder.java --- a/emul/mini/src/main/java/java/lang/AbstractStringBuilder.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/mini/src/main/java/java/lang/AbstractStringBuilder.java Wed Jan 23 22:55:28 2013 +0100 @@ -25,6 +25,8 @@ package java.lang; +import org.apidesign.bck2brwsr.emul.lang.System; + /** * A mutable sequence of characters. *

@@ -350,7 +352,7 @@ throw new StringIndexOutOfBoundsException(srcEnd); if (srcBegin > srcEnd) throw new StringIndexOutOfBoundsException("srcBegin > srcEnd"); - arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin); + System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin); } /** @@ -500,7 +502,7 @@ public AbstractStringBuilder append(char[] str) { int len = str.length; ensureCapacityInternal(count + len); - arraycopy(str, 0, value, count, len); + System.arraycopy(str, 0, value, count, len); count += len; return this; } @@ -530,7 +532,7 @@ public AbstractStringBuilder append(char str[], int offset, int len) { if (len > 0) // let arraycopy report AIOOBE for len < 0 ensureCapacityInternal(count + len); - arraycopy(str, offset, value, count, len); + System.arraycopy(str, offset, value, count, len); count += len; return this; } @@ -683,7 +685,7 @@ throw new StringIndexOutOfBoundsException(); int len = end - start; if (len > 0) { - arraycopy(value, start+len, value, start, count-end); + System.arraycopy(value, start+len, value, start, count-end); count -= len; } return this; @@ -745,7 +747,7 @@ public AbstractStringBuilder deleteCharAt(int index) { if ((index < 0) || (index >= count)) throw new StringIndexOutOfBoundsException(index); - arraycopy(value, index+1, value, index, count-index-1); + System.arraycopy(value, index+1, value, index, count-index-1); count--; return this; } @@ -783,7 +785,7 @@ int newCount = count + len - (end - start); ensureCapacityInternal(newCount); - arraycopy(value, end, value, start + len, count - end); + System.arraycopy(value, end, value, start + len, count - end); str.getChars(value, start); count = newCount; return this; @@ -889,8 +891,8 @@ "offset " + offset + ", len " + len + ", str.length " + str.length); ensureCapacityInternal(count + len); - arraycopy(value, index, value, index + len, count - index); - arraycopy(str, offset, value, index, len); + System.arraycopy(value, index, value, index + len, count - index); + System.arraycopy(str, offset, value, index, len); count += len; return this; } @@ -956,7 +958,7 @@ str = "null"; int len = str.length(); ensureCapacityInternal(count + len); - arraycopy(value, offset, value, offset + len, count - offset); + System.arraycopy(value, offset, value, offset + len, count - offset); str.getChars(value, offset); count += len; return this; @@ -991,8 +993,8 @@ throw new StringIndexOutOfBoundsException(offset); int len = str.length; ensureCapacityInternal(count + len); - arraycopy(value, offset, value, offset + len, count - offset); - arraycopy(str, 0, value, offset, len); + System.arraycopy(value, offset, value, offset + len, count - offset); + System.arraycopy(str, 0, value, offset, len); count += len; return this; } @@ -1082,7 +1084,7 @@ + s.length()); int len = end - start; ensureCapacityInternal(count + len); - arraycopy(value, dstOffset, value, dstOffset + len, + System.arraycopy(value, dstOffset, value, dstOffset + len, count - dstOffset); for (int i=start; i " + to); } char[] copy = new char[newLength]; - arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); + System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); return copy; } - static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) { - if (srcBegin < dstBegin) { - while (count-- > 0) { - dst[dstBegin + count] = value[srcBegin + count]; - } - } else { - while (count-- > 0) { - dst[dstBegin++] = value[srcBegin++]; - } - } - } - // access system property static String getProperty(String nm) { return null; @@ -1417,7 +1407,7 @@ static char[] copyOf(char[] original, int newLength) { char[] copy = new char[newLength]; - arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); + System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); return copy; } diff -r df92e9608039 -r 53fafe384803 emul/mini/src/main/java/java/lang/String.java --- a/emul/mini/src/main/java/java/lang/String.java Wed Jan 23 22:33:45 2013 +0100 +++ b/emul/mini/src/main/java/java/lang/String.java Wed Jan 23 22:55:28 2013 +0100 @@ -30,6 +30,7 @@ import org.apidesign.bck2brwsr.core.JavaScriptBody; import org.apidesign.bck2brwsr.core.JavaScriptOnly; import org.apidesign.bck2brwsr.core.JavaScriptPrototype; +import org.apidesign.bck2brwsr.emul.lang.System; /** * The String class represents character strings. All @@ -787,7 +788,7 @@ "}" ) void getChars(char dst[], int dstBegin) { - AbstractStringBuilder.arraycopy(toCharArray(), offset(), dst, dstBegin, length()); + System.arraycopy(toCharArray(), offset(), dst, dstBegin, length()); } /** @@ -836,7 +837,7 @@ if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } - AbstractStringBuilder.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin, + System.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin, srcEnd - srcBegin); } @@ -2416,7 +2417,7 @@ // * is the write location in result */ // // /* Just copy the first few lowerCase characters. */ -// arraycopy(value, offset, result, 0, firstUpper); +// System.arraycopy(value, offset, result, 0, firstUpper); // // String lang = locale.getLanguage(); // boolean localeDependent = @@ -2462,7 +2463,7 @@ // int mapLen = lowerCharArray.length; // if (mapLen > srcCount) { // char[] result2 = new char[result.length + mapLen - srcCount]; -// arraycopy(result, 0, result2, 0, +// System.arraycopy(result, 0, result2, 0, // i + resultOffset); // result = result2; // } @@ -2584,7 +2585,7 @@ * is the write location in result * /* Just copy the first few upperCase characters. * - arraycopy(value, offset, result, 0, firstLower); + System.arraycopy(value, offset, result, 0, firstLower); String lang = locale.getLanguage(); boolean localeDependent = @@ -2627,7 +2628,7 @@ int mapLen = upperCharArray.length; if (mapLen > srcCount) { char[] result2 = new char[result.length + mapLen - srcCount]; - arraycopy(result, 0, result2, 0, + System.arraycopy(result, 0, result2, 0, i + resultOffset); result = result2; } diff -r df92e9608039 -r 53fafe384803 emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Wed Jan 23 22:55:28 2013 +0100 @@ -0,0 +1,64 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.emul.lang; + +/** + * + * @author Jaroslav Tulach + */ +public class System { + private System() { + } + + public static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) { + if (srcBegin < dstBegin) { + while (count-- > 0) { + dst[dstBegin + count] = value[srcBegin + count]; + } + } else { + while (count-- > 0) { + dst[dstBegin++] = value[srcBegin++]; + } + } + } + + public static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) { + if (srcBegin < dstBegin) { + while (count-- > 0) { + dst[dstBegin + count] = value[srcBegin + count]; + } + } else { + while (count-- > 0) { + dst[dstBegin++] = value[srcBegin++]; + } + } + } + + public static void arraycopy(Object[] value, int srcBegin, Object[] dst, int dstBegin, int count) { + if (srcBegin < dstBegin) { + while (count-- > 0) { + dst[dstBegin + count] = value[srcBegin + count]; + } + } else { + while (count-- > 0) { + dst[dstBegin++] = value[srcBegin++]; + } + } + } + +}