| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 patch class Int8List { | 5 patch class Int8List { |
| 6 /* patch */ factory Int8List(int length) { | 6 /* patch */ factory Int8List(int length) { |
| 7 return new _Int8Array(length); | 7 return new _Int8Array(length); |
| 8 } | 8 } |
| 9 | 9 |
| 10 /* patch */ factory Int8List.transferable(int length) { | 10 /* patch */ factory Int8List.transferable(int length) { |
| (...skipping 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1864 final _ByteArrayBase _array; | 1864 final _ByteArrayBase _array; |
| 1865 final int _offset; | 1865 final int _offset; |
| 1866 final int _length; | 1866 final int _length; |
| 1867 } | 1867 } |
| 1868 | 1868 |
| 1869 | 1869 |
| 1870 // TODO(floitsch): extending the collection adds extra cost (because of type | 1870 // TODO(floitsch): extending the collection adds extra cost (because of type |
| 1871 // parameters). Consider copying the functions from Collection into this class | 1871 // parameters). Consider copying the functions from Collection into this class |
| 1872 // and just implementing Collection<int>. | 1872 // and just implementing Collection<int>. |
| 1873 class _ByteArrayViewBase extends Collection<int> { | 1873 class _ByteArrayViewBase extends Collection<int> { |
| 1874 _ByteArrayViewBase(this._array, this._offset, this.length); |
| 1875 |
| 1874 num operator[](int index); | 1876 num operator[](int index); |
| 1875 | 1877 |
| 1876 // Methods implementing the Collection interface. | 1878 // Methods implementing the Collection interface. |
| 1877 | 1879 |
| 1878 void forEach(void f(element)) { | 1880 void forEach(void f(element)) { |
| 1879 var len = this.length; | 1881 var len = this.length; |
| 1880 for (var i = 0; i < len; i++) { | 1882 for (var i = 0; i < len; i++) { |
| 1881 f(this[i]); | 1883 f(this[i]); |
| 1882 } | 1884 } |
| 1883 } | 1885 } |
| 1884 | 1886 |
| 1885 bool get isEmpty { | 1887 bool get isEmpty { |
| 1886 return this.length == 0; | 1888 return this.length == 0; |
| 1887 } | 1889 } |
| 1888 | 1890 |
| 1889 int get length; | |
| 1890 | |
| 1891 // Methods implementing the List interface. | 1891 // Methods implementing the List interface. |
| 1892 | 1892 |
| 1893 set length(newLength) { | 1893 set length(newLength) { |
| 1894 throw new UnsupportedError( | 1894 throw new UnsupportedError( |
| 1895 "Cannot resize a non-extendable array"); | 1895 "Cannot resize a non-extendable array"); |
| 1896 } | 1896 } |
| 1897 | 1897 |
| 1898 void add(value) { | 1898 void add(value) { |
| 1899 throw new UnsupportedError( | 1899 throw new UnsupportedError( |
| 1900 "Cannot add to a non-extendable array"); | 1900 "Cannot add to a non-extendable array"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1952 | 1952 |
| 1953 void removeRange(int start, int length) { | 1953 void removeRange(int start, int length) { |
| 1954 throw new UnsupportedError( | 1954 throw new UnsupportedError( |
| 1955 "Cannot remove from a non-extendable array"); | 1955 "Cannot remove from a non-extendable array"); |
| 1956 } | 1956 } |
| 1957 | 1957 |
| 1958 void insertRange(int start, int length, [initialValue]) { | 1958 void insertRange(int start, int length, [initialValue]) { |
| 1959 throw new UnsupportedError( | 1959 throw new UnsupportedError( |
| 1960 "Cannot add to a non-extendable array"); | 1960 "Cannot add to a non-extendable array"); |
| 1961 } | 1961 } |
| 1962 |
| 1963 final ByteArray _array; |
| 1964 final int _offset; |
| 1965 final int length; |
| 1962 } | 1966 } |
| 1963 | 1967 |
| 1964 | 1968 |
| 1965 class _Int8ArrayView extends _ByteArrayViewBase implements Int8List { | 1969 class _Int8ArrayView extends _ByteArrayViewBase implements Int8List { |
| 1966 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 1970 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 1967 : _array = array, | 1971 : super(array, _requireInteger(offsetInBytes), |
| 1968 _offset = _requireInteger(offsetInBytes), | 1972 _requireIntegerOrNull( |
| 1969 _length = _requireIntegerOrNull( | 1973 _length, |
| 1970 length, | 1974 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 1971 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 1975 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 1972 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 1973 } | |
| 1974 | |
| 1975 get length { | |
| 1976 return _length; | |
| 1977 } | 1976 } |
| 1978 | 1977 |
| 1979 int operator[](int index) { | 1978 int operator[](int index) { |
| 1980 if (index < 0 || index >= _length) { | 1979 if (index < 0 || index >= length) { |
| 1981 String message = "$index must be in the range [0..$_length)"; | 1980 String message = "$index must be in the range [0..$length)"; |
| 1982 throw new RangeError(message); | 1981 throw new RangeError(message); |
| 1983 } | 1982 } |
| 1984 return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT)); | 1983 return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT)); |
| 1985 } | 1984 } |
| 1986 | 1985 |
| 1987 void operator[]=(int index, int value) { | 1986 void operator[]=(int index, int value) { |
| 1988 if (index < 0 || index >= _length) { | 1987 if (index < 0 || index >= length) { |
| 1989 String message = "$index must be in the range [0..$_length)"; | 1988 String message = "$index must be in the range [0..$length)"; |
| 1990 throw new RangeError(message); | 1989 throw new RangeError(message); |
| 1991 } | 1990 } |
| 1992 _array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value)); | 1991 _array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value)); |
| 1993 } | 1992 } |
| 1994 | 1993 |
| 1995 Iterator<int> get iterator { | 1994 Iterator<int> get iterator { |
| 1996 return new _ByteArrayIterator<int>(this); | 1995 return new _ByteArrayIterator<int>(this); |
| 1997 } | 1996 } |
| 1998 | 1997 |
| 1999 List<int> getRange(int start, int length) { | 1998 List<int> getRange(int start, int length) { |
| 2000 _rangeCheck(this.length, start, length); | 1999 _rangeCheck(this.length, start, length); |
| 2001 List<int> result = new Int8List(length); | 2000 List<int> result = new Int8List(length); |
| 2002 result.setRange(0, length, this, start); | 2001 result.setRange(0, length, this, start); |
| 2003 return result; | 2002 return result; |
| 2004 } | 2003 } |
| 2005 | 2004 |
| 2006 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2005 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2007 Arrays.copy(from, startFrom, this, start, length); | 2006 Arrays.copy(from, startFrom, this, start, length); |
| 2008 } | 2007 } |
| 2009 | 2008 |
| 2010 String toString() { | 2009 String toString() { |
| 2011 return Collections.collectionToString(this); | 2010 return Collections.collectionToString(this); |
| 2012 } | 2011 } |
| 2013 | 2012 |
| 2014 int bytesPerElement() { | 2013 int bytesPerElement() { |
| 2015 return _BYTES_PER_ELEMENT; | 2014 return _BYTES_PER_ELEMENT; |
| 2016 } | 2015 } |
| 2017 | 2016 |
| 2018 int lengthInBytes() { | 2017 int lengthInBytes() { |
| 2019 return _length * _BYTES_PER_ELEMENT; | 2018 return length * _BYTES_PER_ELEMENT; |
| 2020 } | 2019 } |
| 2021 | 2020 |
| 2022 ByteArray asByteArray([int start = 0, int length]) { | 2021 ByteArray asByteArray([int start = 0, int length]) { |
| 2023 if (length == null) { | 2022 if (length == null) { |
| 2024 length = this.lengthInBytes(); | 2023 length = this.lengthInBytes(); |
| 2025 } | 2024 } |
| 2026 _rangeCheck(this.length, start, length); | 2025 _rangeCheck(this.length, start, length); |
| 2027 return _array.subByteArray(_offset + start, length); | 2026 return _array.subByteArray(_offset + start, length); |
| 2028 } | 2027 } |
| 2029 | 2028 |
| 2030 static const int _BYTES_PER_ELEMENT = 1; | 2029 static const int _BYTES_PER_ELEMENT = 1; |
| 2031 final ByteArray _array; | |
| 2032 final int _offset; | |
| 2033 final int _length; | |
| 2034 } | 2030 } |
| 2035 | 2031 |
| 2036 | 2032 |
| 2037 class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List { | 2033 class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List { |
| 2038 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2034 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2039 : _array = array, | 2035 : super(array, _requireInteger(offsetInBytes), |
| 2040 _offset = _requireInteger(offsetInBytes), | 2036 _requireIntegerOrNull( |
| 2041 _length = _requireIntegerOrNull( | 2037 _length, |
| 2042 length, | 2038 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2043 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2039 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2044 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2045 } | |
| 2046 | |
| 2047 get length { | |
| 2048 return _length; | |
| 2049 } | 2040 } |
| 2050 | 2041 |
| 2051 int operator[](int index) { | 2042 int operator[](int index) { |
| 2052 if (index < 0 || index >= _length) { | 2043 if (index < 0 || index >= length) { |
| 2053 String message = "$index must be in the range [0..$_length)"; | 2044 String message = "$index must be in the range [0..$length)"; |
| 2054 throw new RangeError(message); | 2045 throw new RangeError(message); |
| 2055 } | 2046 } |
| 2056 return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT)); | 2047 return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2057 } | 2048 } |
| 2058 | 2049 |
| 2059 void operator[]=(int index, int value) { | 2050 void operator[]=(int index, int value) { |
| 2060 if (index < 0 || index >= _length) { | 2051 if (index < 0 || index >= length) { |
| 2061 String message = "$index must be in the range [0..$_length)"; | 2052 String message = "$index must be in the range [0..$length)"; |
| 2062 throw new RangeError(message); | 2053 throw new RangeError(message); |
| 2063 } | 2054 } |
| 2064 _array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value)); | 2055 _array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value)); |
| 2065 } | 2056 } |
| 2066 | 2057 |
| 2067 Iterator<int> get iterator { | 2058 Iterator<int> get iterator { |
| 2068 return new _ByteArrayIterator<int>(this); | 2059 return new _ByteArrayIterator<int>(this); |
| 2069 } | 2060 } |
| 2070 | 2061 |
| 2071 List<int> getRange(int start, int length) { | 2062 List<int> getRange(int start, int length) { |
| 2072 _rangeCheck(this.length, start, length); | 2063 _rangeCheck(this.length, start, length); |
| 2073 List<int> result = new Uint8List(length); | 2064 List<int> result = new Uint8List(length); |
| 2074 result.setRange(0, length, this, start); | 2065 result.setRange(0, length, this, start); |
| 2075 return result; | 2066 return result; |
| 2076 } | 2067 } |
| 2077 | 2068 |
| 2078 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2069 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2079 Arrays.copy(from, startFrom, this, start, length); | 2070 Arrays.copy(from, startFrom, this, start, length); |
| 2080 } | 2071 } |
| 2081 | 2072 |
| 2082 String toString() { | 2073 String toString() { |
| 2083 return Collections.collectionToString(this); | 2074 return Collections.collectionToString(this); |
| 2084 } | 2075 } |
| 2085 | 2076 |
| 2086 int bytesPerElement() { | 2077 int bytesPerElement() { |
| 2087 return _BYTES_PER_ELEMENT; | 2078 return _BYTES_PER_ELEMENT; |
| 2088 } | 2079 } |
| 2089 | 2080 |
| 2090 int lengthInBytes() { | 2081 int lengthInBytes() { |
| 2091 return _length * _BYTES_PER_ELEMENT; | 2082 return length * _BYTES_PER_ELEMENT; |
| 2092 } | 2083 } |
| 2093 | 2084 |
| 2094 ByteArray asByteArray([int start = 0, int length]) { | 2085 ByteArray asByteArray([int start = 0, int length]) { |
| 2095 if (length == null) { | 2086 if (length == null) { |
| 2096 length = this.lengthInBytes(); | 2087 length = this.lengthInBytes(); |
| 2097 } | 2088 } |
| 2098 _rangeCheck(this.length, start, length); | 2089 _rangeCheck(this.length, start, length); |
| 2099 return _array.subByteArray(_offset + start, length); | 2090 return _array.subByteArray(_offset + start, length); |
| 2100 } | 2091 } |
| 2101 | 2092 |
| 2102 static const int _BYTES_PER_ELEMENT = 1; | 2093 static const int _BYTES_PER_ELEMENT = 1; |
| 2103 final ByteArray _array; | |
| 2104 final int _offset; | |
| 2105 final int _length; | |
| 2106 } | 2094 } |
| 2107 | 2095 |
| 2108 | 2096 |
| 2109 class _Int16ArrayView extends _ByteArrayViewBase implements Int16List { | 2097 class _Int16ArrayView extends _ByteArrayViewBase implements Int16List { |
| 2110 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2098 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2111 : _array = array, | 2099 : super(array, _requireInteger(offsetInBytes), |
| 2112 _offset = _requireInteger(offsetInBytes), | 2100 _requireIntegerOrNull( |
| 2113 _length = _requireIntegerOrNull( | 2101 _length, |
| 2114 length, | 2102 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2115 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2103 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2116 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2117 } | |
| 2118 | |
| 2119 get length { | |
| 2120 return _length; | |
| 2121 } | 2104 } |
| 2122 | 2105 |
| 2123 int operator[](int index) { | 2106 int operator[](int index) { |
| 2124 if (index < 0 || index >= _length) { | 2107 if (index < 0 || index >= length) { |
| 2125 String message = "$index must be in the range [0..$_length)"; | 2108 String message = "$index must be in the range [0..$length)"; |
| 2126 throw new RangeError(message); | 2109 throw new RangeError(message); |
| 2127 } | 2110 } |
| 2128 return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT)); | 2111 return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2129 } | 2112 } |
| 2130 | 2113 |
| 2131 void operator[]=(int index, int value) { | 2114 void operator[]=(int index, int value) { |
| 2132 if (index < 0 || index >= _length) { | 2115 if (index < 0 || index >= length) { |
| 2133 String message = "$index must be in the range [0..$_length)"; | 2116 String message = "$index must be in the range [0..$length)"; |
| 2134 throw new RangeError(message); | 2117 throw new RangeError(message); |
| 2135 } | 2118 } |
| 2136 _array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value)); | 2119 _array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value)); |
| 2137 } | 2120 } |
| 2138 | 2121 |
| 2139 Iterator<int> get iterator { | 2122 Iterator<int> get iterator { |
| 2140 return new _ByteArrayIterator<int>(this); | 2123 return new _ByteArrayIterator<int>(this); |
| 2141 } | 2124 } |
| 2142 | 2125 |
| 2143 List<int> getRange(int start, int length) { | 2126 List<int> getRange(int start, int length) { |
| 2144 _rangeCheck(this.length, start, length); | 2127 _rangeCheck(this.length, start, length); |
| 2145 List<int> result = new Int16List(length); | 2128 List<int> result = new Int16List(length); |
| 2146 result.setRange(0, length, this, start); | 2129 result.setRange(0, length, this, start); |
| 2147 return result; | 2130 return result; |
| 2148 } | 2131 } |
| 2149 | 2132 |
| 2150 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2133 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2151 Arrays.copy(from, startFrom, this, start, length); | 2134 Arrays.copy(from, startFrom, this, start, length); |
| 2152 } | 2135 } |
| 2153 | 2136 |
| 2154 String toString() { | 2137 String toString() { |
| 2155 return Collections.collectionToString(this); | 2138 return Collections.collectionToString(this); |
| 2156 } | 2139 } |
| 2157 | 2140 |
| 2158 int bytesPerElement() { | 2141 int bytesPerElement() { |
| 2159 return _BYTES_PER_ELEMENT; | 2142 return _BYTES_PER_ELEMENT; |
| 2160 } | 2143 } |
| 2161 | 2144 |
| 2162 int lengthInBytes() { | 2145 int lengthInBytes() { |
| 2163 return _length * _BYTES_PER_ELEMENT; | 2146 return length * _BYTES_PER_ELEMENT; |
| 2164 } | 2147 } |
| 2165 | 2148 |
| 2166 ByteArray asByteArray([int start = 0, int length]) { | 2149 ByteArray asByteArray([int start = 0, int length]) { |
| 2167 if (length == null) { | 2150 if (length == null) { |
| 2168 length = this.lengthInBytes(); | 2151 length = this.lengthInBytes(); |
| 2169 } | 2152 } |
| 2170 _rangeCheck(this.length, start, length); | 2153 _rangeCheck(this.length, start, length); |
| 2171 return _array.subByteArray(_offset + start, length); | 2154 return _array.subByteArray(_offset + start, length); |
| 2172 } | 2155 } |
| 2173 | 2156 |
| 2174 static const int _BYTES_PER_ELEMENT = 2; | 2157 static const int _BYTES_PER_ELEMENT = 2; |
| 2175 final ByteArray _array; | |
| 2176 final int _offset; | |
| 2177 final int _length; | |
| 2178 } | 2158 } |
| 2179 | 2159 |
| 2180 | 2160 |
| 2181 class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List { | 2161 class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List { |
| 2182 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2162 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2183 : _array = array, | 2163 : super(array, _requireInteger(offsetInBytes), |
| 2184 _offset = _requireInteger(offsetInBytes), | 2164 _requireIntegerOrNull( |
| 2185 _length = _requireIntegerOrNull( | 2165 _length, |
| 2186 length, | 2166 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2187 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2167 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2188 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2189 } | |
| 2190 | |
| 2191 get length { | |
| 2192 return _length; | |
| 2193 } | 2168 } |
| 2194 | 2169 |
| 2195 int operator[](int index) { | 2170 int operator[](int index) { |
| 2196 if (index < 0 || index >= _length) { | 2171 if (index < 0 || index >= length) { |
| 2197 String message = "$index must be in the range [0..$_length)"; | 2172 String message = "$index must be in the range [0..$length)"; |
| 2198 throw new RangeError(message); | 2173 throw new RangeError(message); |
| 2199 } | 2174 } |
| 2200 return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT)); | 2175 return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2201 } | 2176 } |
| 2202 | 2177 |
| 2203 void operator[]=(int index, int value) { | 2178 void operator[]=(int index, int value) { |
| 2204 if (index < 0 || index >= _length) { | 2179 if (index < 0 || index >= length) { |
| 2205 String message = "$index must be in the range [0..$_length)"; | 2180 String message = "$index must be in the range [0..$length)"; |
| 2206 throw new RangeError(message); | 2181 throw new RangeError(message); |
| 2207 } | 2182 } |
| 2208 _array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value)); | 2183 _array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value)); |
| 2209 } | 2184 } |
| 2210 | 2185 |
| 2211 Iterator<int> get iterator { | 2186 Iterator<int> get iterator { |
| 2212 return new _ByteArrayIterator<int>(this); | 2187 return new _ByteArrayIterator<int>(this); |
| 2213 } | 2188 } |
| 2214 | 2189 |
| 2215 List<int> getRange(int start, int length) { | 2190 List<int> getRange(int start, int length) { |
| 2216 _rangeCheck(this.length, start, length); | 2191 _rangeCheck(this.length, start, length); |
| 2217 List<int> result = new Uint16List(length); | 2192 List<int> result = new Uint16List(length); |
| 2218 result.setRange(0, length, this, start); | 2193 result.setRange(0, length, this, start); |
| 2219 return result; | 2194 return result; |
| 2220 } | 2195 } |
| 2221 | 2196 |
| 2222 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2197 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2223 Arrays.copy(from, startFrom, this, start, length); | 2198 Arrays.copy(from, startFrom, this, start, length); |
| 2224 } | 2199 } |
| 2225 | 2200 |
| 2226 String toString() { | 2201 String toString() { |
| 2227 return Collections.collectionToString(this); | 2202 return Collections.collectionToString(this); |
| 2228 } | 2203 } |
| 2229 | 2204 |
| 2230 int bytesPerElement() { | 2205 int bytesPerElement() { |
| 2231 return _BYTES_PER_ELEMENT; | 2206 return _BYTES_PER_ELEMENT; |
| 2232 } | 2207 } |
| 2233 | 2208 |
| 2234 int lengthInBytes() { | 2209 int lengthInBytes() { |
| 2235 return _length * _BYTES_PER_ELEMENT; | 2210 return length * _BYTES_PER_ELEMENT; |
| 2236 } | 2211 } |
| 2237 | 2212 |
| 2238 ByteArray asByteArray([int start = 0, int length]) { | 2213 ByteArray asByteArray([int start = 0, int length]) { |
| 2239 if (length == null) { | 2214 if (length == null) { |
| 2240 length = this.lengthInBytes(); | 2215 length = this.lengthInBytes(); |
| 2241 } | 2216 } |
| 2242 _rangeCheck(this.length, start, length); | 2217 _rangeCheck(this.length, start, length); |
| 2243 return _array.subByteArray(_offset + start, length); | 2218 return _array.subByteArray(_offset + start, length); |
| 2244 } | 2219 } |
| 2245 | 2220 |
| 2246 static const int _BYTES_PER_ELEMENT = 2; | 2221 static const int _BYTES_PER_ELEMENT = 2; |
| 2247 final ByteArray _array; | |
| 2248 final int _offset; | |
| 2249 final int _length; | |
| 2250 } | 2222 } |
| 2251 | 2223 |
| 2252 | 2224 |
| 2253 class _Int32ArrayView extends _ByteArrayViewBase implements Int32List { | 2225 class _Int32ArrayView extends _ByteArrayViewBase implements Int32List { |
| 2254 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2226 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2255 : _array = array, | 2227 : super(array, _requireInteger(offsetInBytes), |
| 2256 _offset = _requireInteger(offsetInBytes), | 2228 _requireIntegerOrNull( |
| 2257 _length = _requireIntegerOrNull( | 2229 _length, |
| 2258 length, | 2230 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2259 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2231 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2260 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2261 } | |
| 2262 | |
| 2263 get length { | |
| 2264 return _length; | |
| 2265 } | 2232 } |
| 2266 | 2233 |
| 2267 int operator[](int index) { | 2234 int operator[](int index) { |
| 2268 if (index < 0 || index >= _length) { | 2235 if (index < 0 || index >= length) { |
| 2269 String message = "$index must be in the range [0..$_length)"; | 2236 String message = "$index must be in the range [0..$length)"; |
| 2270 throw new RangeError(message); | 2237 throw new RangeError(message); |
| 2271 } | 2238 } |
| 2272 return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT)); | 2239 return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2273 } | 2240 } |
| 2274 | 2241 |
| 2275 void operator[]=(int index, int value) { | 2242 void operator[]=(int index, int value) { |
| 2276 if (index < 0 || index >= _length) { | 2243 if (index < 0 || index >= length) { |
| 2277 String message = "$index must be in the range [0..$_length)"; | 2244 String message = "$index must be in the range [0..$length)"; |
| 2278 throw new RangeError(message); | 2245 throw new RangeError(message); |
| 2279 } | 2246 } |
| 2280 _array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value)); | 2247 _array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value)); |
| 2281 } | 2248 } |
| 2282 | 2249 |
| 2283 Iterator<int> get iterator { | 2250 Iterator<int> get iterator { |
| 2284 return new _ByteArrayIterator<int>(this); | 2251 return new _ByteArrayIterator<int>(this); |
| 2285 } | 2252 } |
| 2286 | 2253 |
| 2287 List<int> getRange(int start, int length) { | 2254 List<int> getRange(int start, int length) { |
| 2288 _rangeCheck(this.length, start, length); | 2255 _rangeCheck(this.length, start, length); |
| 2289 List<int> result = new Int32List(length); | 2256 List<int> result = new Int32List(length); |
| 2290 result.setRange(0, length, this, start); | 2257 result.setRange(0, length, this, start); |
| 2291 return result; | 2258 return result; |
| 2292 } | 2259 } |
| 2293 | 2260 |
| 2294 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2261 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2295 Arrays.copy(from, startFrom, this, start, length); | 2262 Arrays.copy(from, startFrom, this, start, length); |
| 2296 } | 2263 } |
| 2297 | 2264 |
| 2298 String toString() { | 2265 String toString() { |
| 2299 return Collections.collectionToString(this); | 2266 return Collections.collectionToString(this); |
| 2300 } | 2267 } |
| 2301 | 2268 |
| 2302 int bytesPerElement() { | 2269 int bytesPerElement() { |
| 2303 return _BYTES_PER_ELEMENT; | 2270 return _BYTES_PER_ELEMENT; |
| 2304 } | 2271 } |
| 2305 | 2272 |
| 2306 int lengthInBytes() { | 2273 int lengthInBytes() { |
| 2307 return _length * _BYTES_PER_ELEMENT; | 2274 return length * _BYTES_PER_ELEMENT; |
| 2308 } | 2275 } |
| 2309 | 2276 |
| 2310 ByteArray asByteArray([int start = 0, int length]) { | 2277 ByteArray asByteArray([int start = 0, int length]) { |
| 2311 if (length == null) { | 2278 if (length == null) { |
| 2312 length = this.lengthInBytes(); | 2279 length = this.lengthInBytes(); |
| 2313 } | 2280 } |
| 2314 _rangeCheck(this.length, start, length); | 2281 _rangeCheck(this.length, start, length); |
| 2315 return _array.subByteArray(_offset + start, length); | 2282 return _array.subByteArray(_offset + start, length); |
| 2316 } | 2283 } |
| 2317 | 2284 |
| 2318 static const int _BYTES_PER_ELEMENT = 4; | 2285 static const int _BYTES_PER_ELEMENT = 4; |
| 2319 final ByteArray _array; | |
| 2320 final int _offset; | |
| 2321 final int _length; | |
| 2322 } | 2286 } |
| 2323 | 2287 |
| 2324 | 2288 |
| 2325 class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List { | 2289 class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List { |
| 2326 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2290 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2327 : _array = array, | 2291 : super(array, _requireInteger(offsetInBytes), |
| 2328 _offset = _requireInteger(offsetInBytes), | 2292 _requireIntegerOrNull( |
| 2329 _length = _requireIntegerOrNull( | 2293 _length, |
| 2330 length, | 2294 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2331 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2295 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2332 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2333 } | |
| 2334 | |
| 2335 get length { | |
| 2336 return _length; | |
| 2337 } | 2296 } |
| 2338 | 2297 |
| 2339 int operator[](int index) { | 2298 int operator[](int index) { |
| 2340 if (index < 0 || index >= _length) { | 2299 if (index < 0 || index >= length) { |
| 2341 String message = "$index must be in the range [0..$_length)"; | 2300 String message = "$index must be in the range [0..$length)"; |
| 2342 throw new RangeError(message); | 2301 throw new RangeError(message); |
| 2343 } | 2302 } |
| 2344 return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT)); | 2303 return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2345 } | 2304 } |
| 2346 | 2305 |
| 2347 void operator[]=(int index, int value) { | 2306 void operator[]=(int index, int value) { |
| 2348 if (index < 0 || index >= _length) { | 2307 if (index < 0 || index >= length) { |
| 2349 String message = "$index must be in the range [0..$_length)"; | 2308 String message = "$index must be in the range [0..$length)"; |
| 2350 throw new RangeError(message); | 2309 throw new RangeError(message); |
| 2351 } | 2310 } |
| 2352 _array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value)); | 2311 _array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value)); |
| 2353 } | 2312 } |
| 2354 | 2313 |
| 2355 Iterator<int> get iterator { | 2314 Iterator<int> get iterator { |
| 2356 return new _ByteArrayIterator<int>(this); | 2315 return new _ByteArrayIterator<int>(this); |
| 2357 } | 2316 } |
| 2358 | 2317 |
| 2359 List<int> getRange(int start, int length) { | 2318 List<int> getRange(int start, int length) { |
| 2360 _rangeCheck(this.length, start, length); | 2319 _rangeCheck(this.length, start, length); |
| 2361 List<int> result = new Uint32List(length); | 2320 List<int> result = new Uint32List(length); |
| 2362 result.setRange(0, length, this, start); | 2321 result.setRange(0, length, this, start); |
| 2363 return result; | 2322 return result; |
| 2364 } | 2323 } |
| 2365 | 2324 |
| 2366 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2325 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2367 Arrays.copy(from, startFrom, this, start, length); | 2326 Arrays.copy(from, startFrom, this, start, length); |
| 2368 } | 2327 } |
| 2369 | 2328 |
| 2370 String toString() { | 2329 String toString() { |
| 2371 return Collections.collectionToString(this); | 2330 return Collections.collectionToString(this); |
| 2372 } | 2331 } |
| 2373 | 2332 |
| 2374 int bytesPerElement() { | 2333 int bytesPerElement() { |
| 2375 return _BYTES_PER_ELEMENT; | 2334 return _BYTES_PER_ELEMENT; |
| 2376 } | 2335 } |
| 2377 | 2336 |
| 2378 int lengthInBytes() { | 2337 int lengthInBytes() { |
| 2379 return _length * _BYTES_PER_ELEMENT; | 2338 return length * _BYTES_PER_ELEMENT; |
| 2380 } | 2339 } |
| 2381 | 2340 |
| 2382 ByteArray asByteArray([int start = 0, int length]) { | 2341 ByteArray asByteArray([int start = 0, int length]) { |
| 2383 if (length == null) { | 2342 if (length == null) { |
| 2384 length = this.lengthInBytes(); | 2343 length = this.lengthInBytes(); |
| 2385 } | 2344 } |
| 2386 _rangeCheck(this.length, start, length); | 2345 _rangeCheck(this.length, start, length); |
| 2387 return _array.subByteArray(_offset + start, length); | 2346 return _array.subByteArray(_offset + start, length); |
| 2388 } | 2347 } |
| 2389 | 2348 |
| 2390 static const int _BYTES_PER_ELEMENT = 4; | 2349 static const int _BYTES_PER_ELEMENT = 4; |
| 2391 final ByteArray _array; | |
| 2392 final int _offset; | |
| 2393 final int _length; | |
| 2394 } | 2350 } |
| 2395 | 2351 |
| 2396 | 2352 |
| 2397 class _Int64ArrayView extends _ByteArrayViewBase implements Int64List { | 2353 class _Int64ArrayView extends _ByteArrayViewBase implements Int64List { |
| 2398 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2354 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2399 : _array = array, | 2355 : super(array, _requireInteger(offsetInBytes), |
| 2400 _offset = _requireInteger(offsetInBytes), | 2356 _requireIntegerOrNull( |
| 2401 _length = _requireIntegerOrNull( | 2357 _length, |
| 2402 length, | 2358 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2403 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2359 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2404 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2405 } | |
| 2406 | |
| 2407 get length { | |
| 2408 return _length; | |
| 2409 } | 2360 } |
| 2410 | 2361 |
| 2411 int operator[](int index) { | 2362 int operator[](int index) { |
| 2412 if (index < 0 || index >= _length) { | 2363 if (index < 0 || index >= length) { |
| 2413 String message = "$index must be in the range [0..$_length)"; | 2364 String message = "$index must be in the range [0..$length)"; |
| 2414 throw new RangeError(message); | 2365 throw new RangeError(message); |
| 2415 } | 2366 } |
| 2416 return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT)); | 2367 return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2417 } | 2368 } |
| 2418 | 2369 |
| 2419 void operator[]=(int index, int value) { | 2370 void operator[]=(int index, int value) { |
| 2420 if (index < 0 || index >= _length) { | 2371 if (index < 0 || index >= length) { |
| 2421 String message = "$index must be in the range [0..$_length)"; | 2372 String message = "$index must be in the range [0..$length)"; |
| 2422 throw new RangeError(message); | 2373 throw new RangeError(message); |
| 2423 } | 2374 } |
| 2424 _array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value)); | 2375 _array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value)); |
| 2425 } | 2376 } |
| 2426 | 2377 |
| 2427 Iterator<int> get iterator { | 2378 Iterator<int> get iterator { |
| 2428 return new _ByteArrayIterator<int>(this); | 2379 return new _ByteArrayIterator<int>(this); |
| 2429 } | 2380 } |
| 2430 | 2381 |
| 2431 List<int> getRange(int start, int length) { | 2382 List<int> getRange(int start, int length) { |
| 2432 _rangeCheck(this.length, start, length); | 2383 _rangeCheck(this.length, start, length); |
| 2433 List<int> result = new Int64List(length); | 2384 List<int> result = new Int64List(length); |
| 2434 result.setRange(0, length, this, start); | 2385 result.setRange(0, length, this, start); |
| 2435 return result; | 2386 return result; |
| 2436 } | 2387 } |
| 2437 | 2388 |
| 2438 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2389 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2439 Arrays.copy(from, startFrom, this, start, length); | 2390 Arrays.copy(from, startFrom, this, start, length); |
| 2440 } | 2391 } |
| 2441 | 2392 |
| 2442 String toString() { | 2393 String toString() { |
| 2443 return Collections.collectionToString(this); | 2394 return Collections.collectionToString(this); |
| 2444 } | 2395 } |
| 2445 | 2396 |
| 2446 int bytesPerElement() { | 2397 int bytesPerElement() { |
| 2447 return _BYTES_PER_ELEMENT; | 2398 return _BYTES_PER_ELEMENT; |
| 2448 } | 2399 } |
| 2449 | 2400 |
| 2450 int lengthInBytes() { | 2401 int lengthInBytes() { |
| 2451 return _length * _BYTES_PER_ELEMENT; | 2402 return length * _BYTES_PER_ELEMENT; |
| 2452 } | 2403 } |
| 2453 | 2404 |
| 2454 ByteArray asByteArray([int start = 0, int length]) { | 2405 ByteArray asByteArray([int start = 0, int length]) { |
| 2455 if (length == null) { | 2406 if (length == null) { |
| 2456 length = this.lengthInBytes(); | 2407 length = this.lengthInBytes(); |
| 2457 } | 2408 } |
| 2458 _rangeCheck(this.length, start, length); | 2409 _rangeCheck(this.length, start, length); |
| 2459 return _array.subByteArray(_offset + start, length); | 2410 return _array.subByteArray(_offset + start, length); |
| 2460 } | 2411 } |
| 2461 | 2412 |
| 2462 static const int _BYTES_PER_ELEMENT = 8; | 2413 static const int _BYTES_PER_ELEMENT = 8; |
| 2463 final ByteArray _array; | |
| 2464 final int _offset; | |
| 2465 final int _length; | |
| 2466 } | 2414 } |
| 2467 | 2415 |
| 2468 | 2416 |
| 2469 class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List { | 2417 class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List { |
| 2470 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2418 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2471 : _array = array, | 2419 : super(array, _requireInteger(offsetInBytes), |
| 2472 _offset = _requireInteger(offsetInBytes), | 2420 _requireIntegerOrNull( |
| 2473 _length = _requireIntegerOrNull( | 2421 _length, |
| 2474 length, | 2422 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2475 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2423 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2476 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2477 } | |
| 2478 | |
| 2479 get length { | |
| 2480 return _length; | |
| 2481 } | 2424 } |
| 2482 | 2425 |
| 2483 int operator[](int index) { | 2426 int operator[](int index) { |
| 2484 if (index < 0 || index >= _length) { | 2427 if (index < 0 || index >= length) { |
| 2485 String message = "$index must be in the range [0..$_length)"; | 2428 String message = "$index must be in the range [0..$length)"; |
| 2486 throw new RangeError(message); | 2429 throw new RangeError(message); |
| 2487 } | 2430 } |
| 2488 return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT)); | 2431 return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2489 } | 2432 } |
| 2490 | 2433 |
| 2491 void operator[]=(int index, int value) { | 2434 void operator[]=(int index, int value) { |
| 2492 if (index < 0 || index >= _length) { | 2435 if (index < 0 || index >= length) { |
| 2493 String message = "$index must be in the range [0..$_length)"; | 2436 String message = "$index must be in the range [0..$length)"; |
| 2494 throw new RangeError(message); | 2437 throw new RangeError(message); |
| 2495 } | 2438 } |
| 2496 _array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value)); | 2439 _array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value)); |
| 2497 } | 2440 } |
| 2498 | 2441 |
| 2499 Iterator<int> get iterator { | 2442 Iterator<int> get iterator { |
| 2500 return new _ByteArrayIterator<int>(this); | 2443 return new _ByteArrayIterator<int>(this); |
| 2501 } | 2444 } |
| 2502 | 2445 |
| 2503 List<int> getRange(int start, int length) { | 2446 List<int> getRange(int start, int length) { |
| 2504 _rangeCheck(this.length, start, length); | 2447 _rangeCheck(this.length, start, length); |
| 2505 List<int> result = new Uint64List(length); | 2448 List<int> result = new Uint64List(length); |
| 2506 result.setRange(0, length, this, start); | 2449 result.setRange(0, length, this, start); |
| 2507 return result; | 2450 return result; |
| 2508 } | 2451 } |
| 2509 | 2452 |
| 2510 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | 2453 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 2511 Arrays.copy(from, startFrom, this, start, length); | 2454 Arrays.copy(from, startFrom, this, start, length); |
| 2512 } | 2455 } |
| 2513 | 2456 |
| 2514 String toString() { | 2457 String toString() { |
| 2515 return Collections.collectionToString(this); | 2458 return Collections.collectionToString(this); |
| 2516 } | 2459 } |
| 2517 | 2460 |
| 2518 int bytesPerElement() { | 2461 int bytesPerElement() { |
| 2519 return _BYTES_PER_ELEMENT; | 2462 return _BYTES_PER_ELEMENT; |
| 2520 } | 2463 } |
| 2521 | 2464 |
| 2522 int lengthInBytes() { | 2465 int lengthInBytes() { |
| 2523 return _length * _BYTES_PER_ELEMENT; | 2466 return length * _BYTES_PER_ELEMENT; |
| 2524 } | 2467 } |
| 2525 | 2468 |
| 2526 ByteArray asByteArray([int start = 0, int length]) { | 2469 ByteArray asByteArray([int start = 0, int length]) { |
| 2527 if (length == null) { | 2470 if (length == null) { |
| 2528 length = this.lengthInBytes(); | 2471 length = this.lengthInBytes(); |
| 2529 } | 2472 } |
| 2530 _rangeCheck(this.length, start, length); | 2473 _rangeCheck(this.length, start, length); |
| 2531 return _array.subByteArray(_offset + start, length); | 2474 return _array.subByteArray(_offset + start, length); |
| 2532 } | 2475 } |
| 2533 | 2476 |
| 2534 static const int _BYTES_PER_ELEMENT = 8; | 2477 static const int _BYTES_PER_ELEMENT = 8; |
| 2535 final ByteArray _array; | |
| 2536 final int _offset; | |
| 2537 final int _length; | |
| 2538 } | 2478 } |
| 2539 | 2479 |
| 2540 | 2480 |
| 2541 class _Float32ArrayView extends _ByteArrayViewBase implements Float32List { | 2481 class _Float32ArrayView extends _ByteArrayViewBase implements Float32List { |
| 2542 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2482 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2543 : _array = array, | 2483 : super(array, _requireInteger(offsetInBytes), |
| 2544 _offset = _requireInteger(offsetInBytes), | 2484 _requireIntegerOrNull( |
| 2545 _length = _requireIntegerOrNull( | 2485 _length, |
| 2546 length, | 2486 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2547 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2487 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2548 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2549 } | |
| 2550 | |
| 2551 get length { | |
| 2552 return _length; | |
| 2553 } | 2488 } |
| 2554 | 2489 |
| 2555 double operator[](int index) { | 2490 double operator[](int index) { |
| 2556 if (index < 0 || index >= _length) { | 2491 if (index < 0 || index >= length) { |
| 2557 String message = "$index must be in the range [0..$_length)"; | 2492 String message = "$index must be in the range [0..$length)"; |
| 2558 throw new RangeError(message); | 2493 throw new RangeError(message); |
| 2559 } | 2494 } |
| 2560 return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT)); | 2495 return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2561 } | 2496 } |
| 2562 | 2497 |
| 2563 void operator[]=(int index, double value) { | 2498 void operator[]=(int index, double value) { |
| 2564 if (index < 0 || index >= _length) { | 2499 if (index < 0 || index >= length) { |
| 2565 String message = "$index must be in the range [0..$_length)"; | 2500 String message = "$index must be in the range [0..$length)"; |
| 2566 throw new RangeError(message); | 2501 throw new RangeError(message); |
| 2567 } | 2502 } |
| 2568 _array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value); | 2503 _array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value); |
| 2569 } | 2504 } |
| 2570 | 2505 |
| 2571 Iterator<double> get iterator { | 2506 Iterator<double> get iterator { |
| 2572 return new _ByteArrayIterator<double>(this); | 2507 return new _ByteArrayIterator<double>(this); |
| 2573 } | 2508 } |
| 2574 | 2509 |
| 2575 List<double> getRange(int start, int length) { | 2510 List<double> getRange(int start, int length) { |
| 2576 _rangeCheck(this.length, start, length); | 2511 _rangeCheck(this.length, start, length); |
| 2577 List<double> result = new Float32List(length); | 2512 List<double> result = new Float32List(length); |
| 2578 result.setRange(0, length, this, start); | 2513 result.setRange(0, length, this, start); |
| 2579 return result; | 2514 return result; |
| 2580 } | 2515 } |
| 2581 | 2516 |
| 2582 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 2517 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 2583 Arrays.copy(from, startFrom, this, start, length); | 2518 Arrays.copy(from, startFrom, this, start, length); |
| 2584 } | 2519 } |
| 2585 | 2520 |
| 2586 String toString() { | 2521 String toString() { |
| 2587 return Collections.collectionToString(this); | 2522 return Collections.collectionToString(this); |
| 2588 } | 2523 } |
| 2589 | 2524 |
| 2590 int bytesPerElement() { | 2525 int bytesPerElement() { |
| 2591 return _BYTES_PER_ELEMENT; | 2526 return _BYTES_PER_ELEMENT; |
| 2592 } | 2527 } |
| 2593 | 2528 |
| 2594 int lengthInBytes() { | 2529 int lengthInBytes() { |
| 2595 return _length * _BYTES_PER_ELEMENT; | 2530 return length * _BYTES_PER_ELEMENT; |
| 2596 } | 2531 } |
| 2597 | 2532 |
| 2598 ByteArray asByteArray([int start = 0, int length]) { | 2533 ByteArray asByteArray([int start = 0, int length]) { |
| 2599 if (length == null) { | 2534 if (length == null) { |
| 2600 length = this.lengthInBytes(); | 2535 length = this.lengthInBytes(); |
| 2601 } | 2536 } |
| 2602 _rangeCheck(this.length, start, length); | 2537 _rangeCheck(this.length, start, length); |
| 2603 return _array.subByteArray(_offset + start, length); | 2538 return _array.subByteArray(_offset + start, length); |
| 2604 } | 2539 } |
| 2605 | 2540 |
| 2606 static const int _BYTES_PER_ELEMENT = 4; | 2541 static const int _BYTES_PER_ELEMENT = 4; |
| 2607 final ByteArray _array; | |
| 2608 final int _offset; | |
| 2609 final int _length; | |
| 2610 } | 2542 } |
| 2611 | 2543 |
| 2612 | 2544 |
| 2613 class _Float64ArrayView extends _ByteArrayViewBase implements Float64List { | 2545 class _Float64ArrayView extends _ByteArrayViewBase implements Float64List { |
| 2614 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | 2546 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) |
| 2615 : _array = array, | 2547 : super(array, _requireInteger(offsetInBytes), |
| 2616 _offset = _requireInteger(offsetInBytes), | 2548 _requireIntegerOrNull( |
| 2617 _length = _requireIntegerOrNull( | 2549 _length, |
| 2618 length, | 2550 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { |
| 2619 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) { | 2551 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); |
| 2620 _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT); | |
| 2621 } | |
| 2622 | |
| 2623 get length { | |
| 2624 return _length; | |
| 2625 } | 2552 } |
| 2626 | 2553 |
| 2627 double operator[](int index) { | 2554 double operator[](int index) { |
| 2628 if (index < 0 || index >= _length) { | 2555 if (index < 0 || index >= length) { |
| 2629 String message = "$index must be in the range [0..$_length)"; | 2556 String message = "$index must be in the range [0..$length)"; |
| 2630 throw new RangeError(message); | 2557 throw new RangeError(message); |
| 2631 } | 2558 } |
| 2632 return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT)); | 2559 return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT)); |
| 2633 } | 2560 } |
| 2634 | 2561 |
| 2635 void operator[]=(int index, double value) { | 2562 void operator[]=(int index, double value) { |
| 2636 if (index < 0 || index >= _length) { | 2563 if (index < 0 || index >= length) { |
| 2637 String message = "$index must be in the range [0..$_length)"; | 2564 String message = "$index must be in the range [0..$length)"; |
| 2638 throw new RangeError(message); | 2565 throw new RangeError(message); |
| 2639 } | 2566 } |
| 2640 _array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value); | 2567 _array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value); |
| 2641 } | 2568 } |
| 2642 | 2569 |
| 2643 Iterator<double> get iterator { | 2570 Iterator<double> get iterator { |
| 2644 return new _ByteArrayIterator<double>(this); | 2571 return new _ByteArrayIterator<double>(this); |
| 2645 } | 2572 } |
| 2646 | 2573 |
| 2647 List<double> getRange(int start, int length) { | 2574 List<double> getRange(int start, int length) { |
| 2648 _rangeCheck(this.length, start, length); | 2575 _rangeCheck(this.length, start, length); |
| 2649 List<double> result = new Float64List(length); | 2576 List<double> result = new Float64List(length); |
| 2650 result.setRange(0, length, this, start); | 2577 result.setRange(0, length, this, start); |
| 2651 return result; | 2578 return result; |
| 2652 } | 2579 } |
| 2653 | 2580 |
| 2654 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | 2581 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { |
| 2655 Arrays.copy(from, startFrom, this, start, length); | 2582 Arrays.copy(from, startFrom, this, start, length); |
| 2656 } | 2583 } |
| 2657 | 2584 |
| 2658 String toString() { | 2585 String toString() { |
| 2659 return Collections.collectionToString(this); | 2586 return Collections.collectionToString(this); |
| 2660 } | 2587 } |
| 2661 | 2588 |
| 2662 int bytesPerElement() { | 2589 int bytesPerElement() { |
| 2663 return _BYTES_PER_ELEMENT; | 2590 return _BYTES_PER_ELEMENT; |
| 2664 } | 2591 } |
| 2665 | 2592 |
| 2666 int lengthInBytes() { | 2593 int lengthInBytes() { |
| 2667 return _length * _BYTES_PER_ELEMENT; | 2594 return length * _BYTES_PER_ELEMENT; |
| 2668 } | 2595 } |
| 2669 | 2596 |
| 2670 ByteArray asByteArray([int start = 0, int length]) { | 2597 ByteArray asByteArray([int start = 0, int length]) { |
| 2671 if (length == null) { | 2598 if (length == null) { |
| 2672 length = this.lengthInBytes(); | 2599 length = this.lengthInBytes(); |
| 2673 } | 2600 } |
| 2674 _rangeCheck(this.length, start, length); | 2601 _rangeCheck(this.length, start, length); |
| 2675 return _array.subByteArray(_offset + start, length); | 2602 return _array.subByteArray(_offset + start, length); |
| 2676 } | 2603 } |
| 2677 | 2604 |
| 2678 static const int _BYTES_PER_ELEMENT = 8; | 2605 static const int _BYTES_PER_ELEMENT = 8; |
| 2679 final ByteArray _array; | |
| 2680 final int _offset; | |
| 2681 final int _length; | |
| 2682 } | 2606 } |
| OLD | NEW |