| 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 interface ByteArray default _Uint8Array { | 5 interface ByteArray extends List default _InternalByteArray { |
| 6 // TODO: remove constructor and default implementation after dart:io | |
| 7 // is updated to use Uint8Array directly instead of ByteArray | |
| 8 ByteArray(int length); | 6 ByteArray(int length); |
| 9 | 7 |
| 10 int lengthInBytes(); | 8 int get length(); |
| 11 | |
| 12 ByteArray subByteArray([int start, int length]); | |
| 13 | 9 |
| 14 int getInt8(int byteOffset); | 10 int getInt8(int byteOffset); |
| 15 | 11 |
| 16 void setInt8(int byteOffset, int value); | 12 void setInt8(int byteOffset, int value); |
| 17 | 13 |
| 18 int getUint8(int byteOffset); | 14 int getUint8(int byteOffset); |
| 19 | 15 |
| 20 void setUint8(int byteOffset, int value); | 16 void setUint8(int byteOffset, int value); |
| 21 | 17 |
| 22 int getInt16(int byteOffset); | 18 int getInt16(int byteOffset); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 double getFloat32(int byteOffset); | 42 double getFloat32(int byteOffset); |
| 47 | 43 |
| 48 void setFloat32(int byteOffset, double value); | 44 void setFloat32(int byteOffset, double value); |
| 49 | 45 |
| 50 double getFloat64(int byteOffset); | 46 double getFloat64(int byteOffset); |
| 51 | 47 |
| 52 void setFloat64(int byteOffset, double value); | 48 void setFloat64(int byteOffset, double value); |
| 53 } | 49 } |
| 54 | 50 |
| 55 | 51 |
| 56 interface ByteArrayViewable { | 52 class _ByteArrayBase { |
| 57 int bytesPerElement(); | 53 |
| 58 | 54 // Iterable interface |
| 59 int lengthInBytes(); | 55 |
| 60 | 56 Iterator iterator() { |
| 61 ByteArray asByteArray([int offsetInBytes, int lengthInBytes]); | 57 return new _ByteArrayIterator(this); |
| 62 } | 58 } |
| 63 | 59 |
| 64 | 60 // Collection interface |
| 65 interface Int8Array extends List<int>, ByteArrayViewable | |
| 66 default _Int8Array { | |
| 67 Int8Array(int length); | |
| 68 Int8Array.view(ByteArray array, [int start, int length]); | |
| 69 } | |
| 70 | |
| 71 | |
| 72 interface Uint8Array extends List<int>, ByteArrayViewable | |
| 73 default _Uint8Array { | |
| 74 Uint8Array(int length); | |
| 75 Uint8Array.view(ByteArray array, [int start, int length]); | |
| 76 } | |
| 77 | |
| 78 | |
| 79 interface Int16Array extends List<int>, ByteArrayViewable | |
| 80 default _Int16Array { | |
| 81 Int16Array(int length); | |
| 82 Int16Array.view(ByteArray array, [int start, int length]); | |
| 83 } | |
| 84 | |
| 85 | |
| 86 interface Uint16Array extends List<int>, ByteArrayViewable | |
| 87 default _Uint16Array { | |
| 88 Uint16Array(int length); | |
| 89 Uint16Array.view(ByteArray array, [int start, int length]); | |
| 90 } | |
| 91 | |
| 92 | |
| 93 interface Int32Array extends List<int>, ByteArrayViewable | |
| 94 default _Int32Array { | |
| 95 Int32Array(int length); | |
| 96 Int32Array.view(ByteArray array, [int start, int length]); | |
| 97 } | |
| 98 | |
| 99 | |
| 100 interface Uint32Array extends List<int>, ByteArrayViewable | |
| 101 default _Uint32Array { | |
| 102 Uint32Array(int length); | |
| 103 Uint32Array.view(ByteArray array, [int start, int length]); | |
| 104 | |
| 105 } | |
| 106 | |
| 107 | |
| 108 interface Int64Array extends List<int>, ByteArrayViewable | |
| 109 default _Int64Array { | |
| 110 Int64Array(int length); | |
| 111 Int64Array.view(ByteArray array, [int start, int length]); | |
| 112 } | |
| 113 | |
| 114 | |
| 115 interface Uint64Array extends List<int>, ByteArrayViewable | |
| 116 default _Uint64Array { | |
| 117 Uint64Array(int length); | |
| 118 Uint64Array.view(ByteArray array, [int start, int length]); | |
| 119 } | |
| 120 | |
| 121 | |
| 122 interface Float32Array extends List<double>, ByteArrayViewable | |
| 123 default _Float32Array { | |
| 124 Float32Array(int length); | |
| 125 Float32Array.view(ByteArray array, [int start, int length]); | |
| 126 } | |
| 127 | |
| 128 | |
| 129 interface Float64Array extends List<double>, ByteArrayViewable | |
| 130 default _Float64Array { | |
| 131 Float64Array(int length); | |
| 132 Float64Array.view(ByteArray array, [int start, int length]); | |
| 133 } | |
| 134 | |
| 135 | |
| 136 abstract class _ByteArrayBase { | |
| 137 void add(value) { | |
| 138 throw const UnsupportedOperationException( | |
| 139 "Cannot add to a non-extendable array"); | |
| 140 } | |
| 141 | |
| 142 void addLast(value) { | |
| 143 throw const UnsupportedOperationException( | |
| 144 "Cannot add to a non-extendable array"); | |
| 145 } | |
| 146 | |
| 147 void addAll(Collection value) { | |
| 148 throw const UnsupportedOperationException( | |
| 149 "Cannot add to a non-extendable array"); | |
| 150 } | |
| 151 | |
| 152 void clear() { | |
| 153 throw const UnsupportedOperationException( | |
| 154 "Cannot remove from a non-extendable array"); | |
| 155 } | |
| 156 | |
| 157 void insertRange(int start, int length, [initialValue]) { | |
| 158 throw const UnsupportedOperationException( | |
| 159 "Cannot add to a non-extendable array"); | |
| 160 } | |
| 161 | 61 |
| 162 int get length() { | 62 int get length() { |
| 163 return _length(); | 63 return _length(); |
| 164 } | 64 } |
| 165 | 65 |
| 166 set length(newLength) { | 66 bool every(bool f(int element)) { |
| 167 throw const UnsupportedOperationException( | 67 return Collections.every(this, f); |
| 168 "Cannot resize a non-extendable array"); | 68 } |
| 69 |
| 70 Collection map(f(int element)) { |
| 71 return Collections.map(this, |
| 72 new GrowableObjectArray.withCapacity(length), |
| 73 f); |
| 74 } |
| 75 |
| 76 Collection filter(bool f(int element)) { |
| 77 return Collections.filter(this, new GrowableObjectArray(), f); |
| 78 } |
| 79 |
| 80 void forEach(f(int element)) { |
| 81 Collections.forEach(this, f); |
| 82 } |
| 83 |
| 84 bool isEmpty() { |
| 85 return this.length === 0; |
| 86 } |
| 87 |
| 88 bool some(bool f(int element)) { |
| 89 return Collections.some(this, f); |
| 90 } |
| 91 |
| 92 // List interface |
| 93 |
| 94 int operator[](int index) { |
| 95 return getUint8(index); |
| 96 } |
| 97 |
| 98 void operator[]=(int index, int value) { |
| 99 setUint8(index, value); |
| 100 } |
| 101 |
| 102 void set length(int newLength) { |
| 103 throw const UnsupportedOperationException("Cannot add to a byte array"); |
| 104 } |
| 105 |
| 106 void add(int element) { |
| 107 throw const UnsupportedOperationException("Cannot add to a byte array"); |
| 108 } |
| 109 |
| 110 void addLast(int element) { |
| 111 add(element); |
| 112 } |
| 113 |
| 114 void addAll(Collection elements) { |
| 115 throw const UnsupportedOperationException("Cannot add to a byte array"); |
| 116 } |
| 117 |
| 118 void sort(int compare(int a, b)) { |
| 119 DualPivotQuicksort.sort(this, compare); |
| 120 } |
| 121 |
| 122 int indexOf(int element, [int start = 0]) { |
| 123 return Arrays.indexOf(this, element, start, this.length); |
| 124 } |
| 125 |
| 126 int lastIndexOf(int element, [int start = null]) { |
| 127 if (start === null) start = length - 1; |
| 128 return Arrays.lastIndexOf(this, element, start); |
| 129 } |
| 130 |
| 131 void clear() { |
| 132 throw const UnsupportedOperationException("Cannot clear a byte array"); |
| 169 } | 133 } |
| 170 | 134 |
| 171 int removeLast() { | 135 int removeLast() { |
| 172 throw const UnsupportedOperationException( | 136 throw const UnsupportedOperationException( |
| 173 "Cannot remove from a non-extendable array"); | 137 "Cannot remove from a byte array"); |
| 174 } | 138 } |
| 175 | 139 |
| 176 void removeRange(int start, int length) { | 140 int last() { |
| 177 throw const UnsupportedOperationException( | 141 return this[length - 1]; |
| 178 "Cannot remove from a non-extendable array"); | 142 } |
| 179 } | 143 |
| 180 | 144 String toString() { |
| 181 ByteArray asByteArray([int offsetInBytes = 0, int lengthInBytes]) { | 145 return Collections.collectionToString(this); |
| 182 if (lengthInBytes === null) { | 146 } |
| 183 lengthInBytes = this.lengthInBytes(); | 147 |
| 148 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 149 if (length < 0) { |
| 150 throw new IllegalArgumentException("negative length $length"); |
| 184 } | 151 } |
| 185 return new _ByteArrayView(this, offsetInBytes, lengthInBytes); | 152 if (from is ByteArray) { |
| 186 } | 153 _setRange(start, length, from, startFrom); |
| 187 | |
| 188 int _length() native "ByteArray_getLength"; | |
| 189 | |
| 190 void _setRange(int startInBytes, int lengthInBytes, | |
| 191 _ByteArrayBase from, int startFromInBytes) | |
| 192 native "ByteArray_setRange"; | |
| 193 | |
| 194 int _getInt8(int byteOffset) native "ByteArray_getInt8"; | |
| 195 void _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; | |
| 196 | |
| 197 int _getUint8(int byteOffset) native "ByteArray_getUint8"; | |
| 198 void _setUint8(int byteOffset, int value) native "ByteArray_setUint8"; | |
| 199 | |
| 200 int _getInt16(int byteOffset) native "ByteArray_getInt16"; | |
| 201 void _setInt16(int byteOffset, int value) native "ByteArray_setInt16"; | |
| 202 | |
| 203 int _getUint16(int byteOffset) native "ByteArray_getUint16"; | |
| 204 void _setUint16(int byteOffset, int value) native "ByteArray_setUint16"; | |
| 205 | |
| 206 int _getInt32(int byteOffset) native "ByteArray_getInt32"; | |
| 207 void _setInt32(int byteOffset, int value) native "ByteArray_setInt32"; | |
| 208 | |
| 209 int _getUint32(int byteOffset) native "ByteArray_getUint32"; | |
| 210 void _setUint32(int byteOffset, int value) native "ByteArray_setUint32"; | |
| 211 | |
| 212 int _getInt64(int byteOffset) native "ByteArray_getInt64"; | |
| 213 void _setInt64(int byteOffset, int value) native "ByteArray_setInt64"; | |
| 214 | |
| 215 int _getUint64(int byteOffset) native "ByteArray_getUint64"; | |
| 216 void _setUint64(int byteOffset, int value) native "ByteArray_setUint64"; | |
| 217 | |
| 218 double _getFloat32(int byteOffset) native "ByteArray_getFloat32"; | |
| 219 void _setFloat32(int byteOffset, double value) native "ByteArray_setFloat32"; | |
| 220 | |
| 221 double _getFloat64(int byteOffset) native "ByteArray_getFloat64"; | |
| 222 void _setFloat64(int byteOffset, double value) native "ByteArray_setFloat64"; | |
| 223 } | |
| 224 | |
| 225 | |
| 226 int _toInt(int value, int mask) { | |
| 227 value &= mask; | |
| 228 if (value > (mask >> 1)) value -= mask + 1; | |
| 229 return value; | |
| 230 } | |
| 231 | |
| 232 int _toInt8(int value) { | |
| 233 return _toInt(value, 0xFF); | |
| 234 } | |
| 235 int _toUint8(int value) { | |
| 236 return value & 0xFF; | |
| 237 } | |
| 238 | |
| 239 | |
| 240 int _toInt16(int value) { | |
| 241 return _toInt(value, 0xFFFF); | |
| 242 } | |
| 243 int _toUint16(int value) { | |
| 244 return value & 0xFFFF; | |
| 245 } | |
| 246 | |
| 247 | |
| 248 int _toInt32(int value) { | |
| 249 return _toInt(value, 0xFFFFFFFF); | |
| 250 } | |
| 251 int _toUint32(int value) { | |
| 252 return value & 0xFFFFFFFF; | |
| 253 } | |
| 254 | |
| 255 | |
| 256 int _toInt64(int value) { | |
| 257 return _toInt(value, 0xFFFFFFFFFFFFFFFF); | |
| 258 } | |
| 259 int _toUint64(int value) { | |
| 260 return value & 0xFFFFFFFFFFFFFFFF; | |
| 261 } | |
| 262 | |
| 263 | |
| 264 void _rangeCheck(List a, int start, int length) { | |
| 265 if (length < 0) { | |
| 266 throw new IllegalArgumentException("negative length $length"); | |
| 267 } | |
| 268 if (start < 0) { | |
| 269 throw new IndexOutOfRangeException("negative start $start"); | |
| 270 } | |
| 271 if (start + length > a.length) { | |
| 272 throw new IndexOutOfRangeException(start + length); | |
| 273 } | |
| 274 } | |
| 275 | |
| 276 | |
| 277 class _Int8Array extends _ByteArrayBase implements Int8Array { | |
| 278 factory _Int8Array(int length) { | |
| 279 return _new(length); | |
| 280 } | |
| 281 | |
| 282 factory _Int8Array.view(ByteArray array, [int start = 0, int length]) { | |
| 283 if (length === null) { | |
| 284 length = array.lengthInBytes(); | |
| 285 } | |
| 286 return new _Int8ArrayView(array, start, length); | |
| 287 } | |
| 288 | |
| 289 int operator[](int index) { | |
| 290 return _getIndexed(index); | |
| 291 } | |
| 292 | |
| 293 void operator[]=(int index, int value) { | |
| 294 _setIndexed(index, _toInt8(value)); | |
| 295 } | |
| 296 | |
| 297 Iterator<int> iterator() { | |
| 298 return new _ByteArrayIterator<int>(this); | |
| 299 } | |
| 300 | |
| 301 List<int> getRange(int start, int length) { | |
| 302 _rangeCheck(this, start, length); | |
| 303 _Int8Array result = _new(length); | |
| 304 result.setRange(0, length, this, start); | |
| 305 return result; | |
| 306 } | |
| 307 | |
| 308 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 309 if (from is _Int8Array) { | |
| 310 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 311 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 312 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 313 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 314 } else { | 154 } else { |
| 315 Arrays.copy(from, startFrom, this, start, length); | 155 Arrays.copy(from, startFrom, this, start, length); |
| 316 } | 156 } |
| 317 } | 157 } |
| 318 | 158 |
| 319 String toString() { | 159 List getRange(int start, int length) { |
| 320 return Collections.collectionToString(this); | 160 if (length == 0) return []; |
| 321 } | 161 Arrays.rangeCheck(this, start, length); |
| 322 | 162 ByteArray list = new ByteArray(length); |
| 323 int bytesPerElement() { | 163 list._setRange(0, length, this, start); |
| 324 return _BYTES_PER_ELEMENT; | 164 return list; |
| 325 } | 165 } |
| 326 | 166 |
| 327 int lengthInBytes() { | 167 // Implementation |
| 328 return _length() * _BYTES_PER_ELEMENT; | 168 |
| 329 } | 169 static final int _UINT8_MAX = (1 << 8) - 1; |
| 330 | 170 static final int _UINT16_MAX = (1 << 16) - 1; |
| 331 static final int _BYTES_PER_ELEMENT = 1; | 171 static final int _UINT32_MAX = (1 << 32) - 1; |
| 332 | 172 static final int _UINT64_MAX = (1 << 64) - 1; |
| 333 static _Int8Array _new(int length) native "Int8Array_new"; | 173 |
| 334 | 174 int _toInt(int value, int mask) { |
| 335 int _getIndexed(int index) native "Int8Array_getIndexed"; | 175 int result = value & mask; |
| 336 | 176 return result > (mask >> 1) ? (result - mask) : result; |
| 337 void _setIndexed(int index, int value) native "Int8Array_setIndexed"; | 177 } |
| 178 |
| 179 int _toInt8(int value) { |
| 180 return _toInt(value, _UINT8_MAX); |
| 181 } |
| 182 |
| 183 int _toUint8(int value) { |
| 184 return value & _UINT8_MAX; |
| 185 } |
| 186 |
| 187 int _toInt16(int value) { |
| 188 return _toInt(value, _UINT16_MAX); |
| 189 } |
| 190 |
| 191 int _toUint16(int value) { |
| 192 return value & _UINT16_MAX; |
| 193 } |
| 194 |
| 195 int _toInt32(int value) { |
| 196 return _toInt(value, _UINT32_MAX); |
| 197 } |
| 198 |
| 199 int _toUint32(int value) { |
| 200 return value & _UINT32_MAX; |
| 201 } |
| 202 |
| 203 int _toInt64(int value) { |
| 204 return _toInt(value, _UINT64_MAX); |
| 205 } |
| 206 |
| 207 int _toUint64(int value) { |
| 208 return value & _UINT64_MAX; |
| 209 } |
| 210 |
| 211 int _length() native "ByteArray_getLength"; |
| 212 |
| 213 void _setRange(int start, int length, ByteArray from, int startFrom) |
| 214 native "ByteArray_setRange"; |
| 338 } | 215 } |
| 339 | 216 |
| 340 | 217 |
| 341 class _Uint8Array extends _ByteArrayBase implements Uint8Array { | 218 class _ByteArrayIterator implements Iterator { |
| 342 factory _Uint8Array(int length) { | 219 _ByteArrayIterator(List byteArray) |
| 343 return _new(length); | 220 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { |
| 344 } | 221 assert(byteArray is ByteArray); |
| 345 | 222 } |
| 346 factory _Uint8Array.view(ByteArray array, [int start = 0, int length]) { | |
| 347 if (length === null) { | |
| 348 length = array.lengthInBytes(); | |
| 349 } | |
| 350 return new _Uint8ArrayView(array, start, length); | |
| 351 } | |
| 352 | |
| 353 factory ByteArray(int length) { return _new(length); } // TODO | |
| 354 | |
| 355 int operator[](int index) { | |
| 356 return _getIndexed(index); | |
| 357 } | |
| 358 | |
| 359 void operator[]=(int index, int value) { | |
| 360 _setIndexed(index, _toUint8(value)); | |
| 361 } | |
| 362 | |
| 363 Iterator<int> iterator() { | |
| 364 return new _ByteArrayIterator<int>(this); | |
| 365 } | |
| 366 | |
| 367 List<int> getRange(int start, int length) { | |
| 368 _rangeCheck(this, start, length); | |
| 369 _Uint8Array result = _new(length); | |
| 370 result.setRange(0, length, this, start); | |
| 371 return result; | |
| 372 } | |
| 373 | |
| 374 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 375 if (from is _Uint8Array) { | |
| 376 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 377 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 378 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 379 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 380 } else { | |
| 381 Arrays.copy(from, startFrom, this, start, length); | |
| 382 } | |
| 383 } | |
| 384 | |
| 385 String toString() { | |
| 386 return Collections.collectionToString(this); | |
| 387 } | |
| 388 | |
| 389 int bytesPerElement() { | |
| 390 return _BYTES_PER_ELEMENT; | |
| 391 } | |
| 392 | |
| 393 int lengthInBytes() { | |
| 394 return _length() * _BYTES_PER_ELEMENT; | |
| 395 } | |
| 396 | |
| 397 static final int _BYTES_PER_ELEMENT = 1; | |
| 398 | |
| 399 static _Uint8Array _new(int length) native "Uint8Array_new"; | |
| 400 | |
| 401 int _getIndexed(int index) native "Uint8Array_getIndexed"; | |
| 402 | |
| 403 void _setIndexed(int index, int value) native "Uint8Array_setIndexed"; | |
| 404 } | |
| 405 | |
| 406 | |
| 407 class _Int16Array extends _ByteArrayBase implements Int16Array { | |
| 408 factory _Int16Array(int length) { | |
| 409 return _new(length); | |
| 410 } | |
| 411 | |
| 412 factory _Int16Array.view(ByteArray array, [int start = 0, int length]) { | |
| 413 if (length === null) { | |
| 414 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 415 } | |
| 416 return new _Int16ArrayView(array, start, length); | |
| 417 } | |
| 418 | |
| 419 int operator[](int index) { | |
| 420 return _getIndexed(index); | |
| 421 } | |
| 422 | |
| 423 void operator[]=(int index, int value) { | |
| 424 _setIndexed(index, _toInt16(value)); | |
| 425 } | |
| 426 | |
| 427 Iterator<int> iterator() { | |
| 428 return new _ByteArrayIterator<int>(this); | |
| 429 } | |
| 430 | |
| 431 List<int> getRange(int start, int length) { | |
| 432 _rangeCheck(this, start, length); | |
| 433 _Int16Array result = _new(length); | |
| 434 result.setRange(0, length, this, start); | |
| 435 return result; | |
| 436 } | |
| 437 | |
| 438 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 439 if (from is _Int16Array) { | |
| 440 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 441 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 442 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 443 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 444 } else { | |
| 445 Arrays.copy(from, startFrom, this, start, length); | |
| 446 } | |
| 447 } | |
| 448 | |
| 449 String toString() { | |
| 450 return Collections.collectionToString(this); | |
| 451 } | |
| 452 | |
| 453 int bytesPerElement() { | |
| 454 return _BYTES_PER_ELEMENT; | |
| 455 } | |
| 456 | |
| 457 int lengthInBytes() { | |
| 458 return _length() * _BYTES_PER_ELEMENT; | |
| 459 } | |
| 460 | |
| 461 static final int _BYTES_PER_ELEMENT = 2; | |
| 462 | |
| 463 static _Int16Array _new(int length) native "Int16Array_new"; | |
| 464 | |
| 465 int _getIndexed(int index) native "Int16Array_getIndexed"; | |
| 466 | |
| 467 void _setIndexed(int index, int value) native "Int16Array_setIndexed"; | |
| 468 } | |
| 469 | |
| 470 | |
| 471 class _Uint16Array extends _ByteArrayBase implements Uint16Array { | |
| 472 factory _Uint16Array(int length) { | |
| 473 return _new(length); | |
| 474 } | |
| 475 | |
| 476 factory _Uint16Array.view(ByteArray array, [int start = 0, int length]) { | |
| 477 if (length === null) { | |
| 478 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 479 } | |
| 480 return new _Uint16ArrayView(array, start, length); | |
| 481 } | |
| 482 | |
| 483 int operator[](int index) { | |
| 484 return _getIndexed(index); | |
| 485 } | |
| 486 | |
| 487 void operator[]=(int index, int value) { | |
| 488 _setIndexed(index, _toUint16(value)); | |
| 489 } | |
| 490 | |
| 491 Iterator<int> iterator() { | |
| 492 return new _ByteArrayIterator<int>(this); | |
| 493 } | |
| 494 | |
| 495 List<int> getRange(int start, int length) { | |
| 496 _rangeCheck(this, start, length); | |
| 497 _Uint16Array result = _new(length); | |
| 498 result.setRange(0, length, this, start); | |
| 499 return result; | |
| 500 } | |
| 501 | |
| 502 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 503 if (from is _Uint16Array) { | |
| 504 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 505 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 506 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 507 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 508 } else { | |
| 509 Arrays.copy(from, startFrom, this, start, length); | |
| 510 } | |
| 511 } | |
| 512 | |
| 513 String toString() { | |
| 514 return Collections.collectionToString(this); | |
| 515 } | |
| 516 | |
| 517 int bytesPerElement() { | |
| 518 return _BYTES_PER_ELEMENT; | |
| 519 } | |
| 520 | |
| 521 int lengthInBytes() { | |
| 522 return _length() * _BYTES_PER_ELEMENT; | |
| 523 } | |
| 524 | |
| 525 static final int _BYTES_PER_ELEMENT = 2; | |
| 526 | |
| 527 static _Uint16Array _new(int length) native "Uint16Array_new"; | |
| 528 | |
| 529 int _getIndexed(int index) native "Uint16Array_getIndexed"; | |
| 530 | |
| 531 void _setIndexed(int index, int value) native "Uint16Array_setIndexed"; | |
| 532 } | |
| 533 | |
| 534 | |
| 535 class _Int32Array extends _ByteArrayBase implements Int32Array { | |
| 536 factory _Int32Array(int length) { | |
| 537 return _new(length); | |
| 538 } | |
| 539 | |
| 540 factory _Int32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 541 if (length === null) { | |
| 542 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 543 } | |
| 544 return new _Int32ArrayView(array, start, length); | |
| 545 } | |
| 546 | |
| 547 int operator[](int index) { | |
| 548 return _getIndexed(index); | |
| 549 } | |
| 550 | |
| 551 void operator[]=(int index, int value) { | |
| 552 _setIndexed(index, _toInt32(value)); | |
| 553 } | |
| 554 | |
| 555 Iterator<int> iterator() { | |
| 556 return new _ByteArrayIterator<int>(this); | |
| 557 } | |
| 558 | |
| 559 List<int> getRange(int start, int length) { | |
| 560 _rangeCheck(this, start, length); | |
| 561 _Int32Array result = _new(length); | |
| 562 result.setRange(0, length, this, start); | |
| 563 return result; | |
| 564 } | |
| 565 | |
| 566 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 567 if (from is _Int32Array) { | |
| 568 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 569 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 570 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 571 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 572 } else { | |
| 573 Arrays.copy(from, startFrom, this, start, length); | |
| 574 } | |
| 575 } | |
| 576 | |
| 577 String toString() { | |
| 578 return Collections.collectionToString(this); | |
| 579 } | |
| 580 | |
| 581 int bytesPerElement() { | |
| 582 return _BYTES_PER_ELEMENT; | |
| 583 } | |
| 584 | |
| 585 int lengthInBytes() { | |
| 586 return _length() * _BYTES_PER_ELEMENT; | |
| 587 } | |
| 588 | |
| 589 static final int _BYTES_PER_ELEMENT = 4; | |
| 590 | |
| 591 static _Int32Array _new(int length) native "Int32Array_new"; | |
| 592 | |
| 593 int _getIndexed(int index) native "Int32Array_getIndexed"; | |
| 594 | |
| 595 void _setIndexed(int index, int value) native "Int32Array_setIndexed"; | |
| 596 } | |
| 597 | |
| 598 | |
| 599 class _Uint32Array extends _ByteArrayBase implements Uint32Array { | |
| 600 factory _Uint32Array(int length) { | |
| 601 return _new(length); | |
| 602 } | |
| 603 | |
| 604 factory _Uint32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 605 if (length === null) { | |
| 606 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 607 } | |
| 608 return new _Uint32ArrayView(array, start, length); | |
| 609 } | |
| 610 | |
| 611 int operator[](int index) { | |
| 612 return _getIndexed(index); | |
| 613 } | |
| 614 | |
| 615 void operator[]=(int index, int value) { | |
| 616 _setIndexed(index, _toUint32(value)); | |
| 617 } | |
| 618 | |
| 619 Iterator<int> iterator() { | |
| 620 return new _ByteArrayIterator<int>(this); | |
| 621 } | |
| 622 | |
| 623 List<int> getRange(int start, int length) { | |
| 624 _rangeCheck(this, start, length); | |
| 625 _Uint32Array result = _new(length); | |
| 626 result.setRange(0, length, this, start); | |
| 627 return result; | |
| 628 } | |
| 629 | |
| 630 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 631 if (from is _Uint32Array) { | |
| 632 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 633 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 634 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 635 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 636 } else { | |
| 637 Arrays.copy(from, startFrom, this, start, length); | |
| 638 } | |
| 639 } | |
| 640 | |
| 641 String toString() { | |
| 642 return Collections.collectionToString(this); | |
| 643 } | |
| 644 | |
| 645 int bytesPerElement() { | |
| 646 return _BYTES_PER_ELEMENT; | |
| 647 } | |
| 648 | |
| 649 int lengthInBytes() { | |
| 650 return _length() * _BYTES_PER_ELEMENT; | |
| 651 } | |
| 652 | |
| 653 static final int _BYTES_PER_ELEMENT = 4; | |
| 654 | |
| 655 static _Uint32Array _new(int length) native "Uint32Array_new"; | |
| 656 | |
| 657 int _getIndexed(int index) native "Uint32Array_getIndexed"; | |
| 658 | |
| 659 void _setIndexed(int index, int value) native "Uint32Array_setIndexed"; | |
| 660 } | |
| 661 | |
| 662 | |
| 663 class _Int64Array extends _ByteArrayBase implements Int64Array { | |
| 664 factory _Int64Array(int length) { | |
| 665 return _new(length); | |
| 666 } | |
| 667 | |
| 668 factory _Int64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 669 if (length === null) { | |
| 670 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 671 } | |
| 672 return new _Int64ArrayView(array, start, length); | |
| 673 } | |
| 674 | |
| 675 int operator[](int index) { | |
| 676 return _getIndexed(index); | |
| 677 } | |
| 678 | |
| 679 void operator[]=(int index, int value) { | |
| 680 _setIndexed(index, _toInt64(value)); | |
| 681 } | |
| 682 | |
| 683 Iterator<int> iterator() { | |
| 684 return new _ByteArrayIterator<int>(this); | |
| 685 } | |
| 686 | |
| 687 List<int> getRange(int start, int length) { | |
| 688 _rangeCheck(this, start, length); | |
| 689 _Int64Array result = _new(length); | |
| 690 result.setRange(0, length, this, start); | |
| 691 return result; | |
| 692 } | |
| 693 | |
| 694 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 695 if (from is _Int64Array) { | |
| 696 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 697 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 698 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 699 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 700 } else { | |
| 701 Arrays.copy(from, startFrom, this, start, length); | |
| 702 } | |
| 703 } | |
| 704 | |
| 705 String toString() { | |
| 706 return Collections.collectionToString(this); | |
| 707 } | |
| 708 | |
| 709 int bytesPerElement() { | |
| 710 return _BYTES_PER_ELEMENT; | |
| 711 } | |
| 712 | |
| 713 int lengthInBytes() { | |
| 714 return _length() * _BYTES_PER_ELEMENT; | |
| 715 } | |
| 716 | |
| 717 static final int _BYTES_PER_ELEMENT = 8; | |
| 718 | |
| 719 static _Int64Array _new(int length) native "Int64Array_new"; | |
| 720 | |
| 721 int _getIndexed(int index) native "Int64Array_getIndexed"; | |
| 722 | |
| 723 void _setIndexed(int index, int value) native "Int64Array_setIndexed"; | |
| 724 } | |
| 725 | |
| 726 | |
| 727 class _Uint64Array extends _ByteArrayBase implements Uint64Array { | |
| 728 factory _Uint64Array(int length) { | |
| 729 return _new(length); | |
| 730 } | |
| 731 | |
| 732 factory _Uint64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 733 if (length === null) { | |
| 734 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 735 } | |
| 736 return new _Uint64ArrayView(array, start, length); | |
| 737 } | |
| 738 | |
| 739 int operator[](int index) { | |
| 740 return _getIndexed(index); | |
| 741 } | |
| 742 | |
| 743 void operator[]=(int index, int value) { | |
| 744 _setIndexed(index, _toUint64(value)); | |
| 745 } | |
| 746 | |
| 747 Iterator<int> iterator() { | |
| 748 return new _ByteArrayIterator<int>(this); | |
| 749 } | |
| 750 | |
| 751 List<int> getRange(int start, int length) { | |
| 752 _rangeCheck(this, start, length); | |
| 753 _Uint64Array result = _new(length); | |
| 754 result.setRange(0, length, this, start); | |
| 755 return result; | |
| 756 } | |
| 757 | |
| 758 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 759 if (from is _Uint64Array) { | |
| 760 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 761 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 762 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 763 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 764 } else { | |
| 765 Arrays.copy(from, startFrom, this, start, length); | |
| 766 } | |
| 767 } | |
| 768 | |
| 769 String toString() { | |
| 770 return Collections.collectionToString(this); | |
| 771 } | |
| 772 | |
| 773 int bytesPerElement() { | |
| 774 return _BYTES_PER_ELEMENT; | |
| 775 } | |
| 776 | |
| 777 int lengthInBytes() { | |
| 778 return _length() * _BYTES_PER_ELEMENT; | |
| 779 } | |
| 780 | |
| 781 static final int _BYTES_PER_ELEMENT = 8; | |
| 782 | |
| 783 static _Uint64Array _new(int length) native "Uint64Array_new"; | |
| 784 | |
| 785 int _getIndexed(int index) native "Uint64Array_getIndexed"; | |
| 786 | |
| 787 void _setIndexed(int index, int value) native "Uint64Array_setIndexed"; | |
| 788 } | |
| 789 | |
| 790 | |
| 791 class _Float32Array extends _ByteArrayBase implements Float32Array { | |
| 792 factory _Float32Array(int length) { | |
| 793 return _new(length); | |
| 794 } | |
| 795 | |
| 796 factory _Float32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 797 if (length === null) { | |
| 798 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 799 } | |
| 800 return new _Float32ArrayView(array, start, length); | |
| 801 } | |
| 802 | |
| 803 double operator[](int index) { | |
| 804 return _getIndexed(index); | |
| 805 } | |
| 806 | |
| 807 void operator[]=(int index, double value) { | |
| 808 _setIndexed(index, value); | |
| 809 } | |
| 810 | |
| 811 Iterator<double> iterator() { | |
| 812 return new _ByteArrayIterator<double>(this); | |
| 813 } | |
| 814 | |
| 815 List<double> getRange(int start, int length) { | |
| 816 _rangeCheck(this, start, length); | |
| 817 _Float32Array result = _new(length); | |
| 818 result.setRange(0, length, this, start); | |
| 819 return result; | |
| 820 } | |
| 821 | |
| 822 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 823 if (from is _Float32Array) { | |
| 824 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 825 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 826 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 827 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 828 } else { | |
| 829 Arrays.copy(from, startFrom, this, start, length); | |
| 830 } | |
| 831 } | |
| 832 | |
| 833 String toString() { | |
| 834 return Collections.collectionToString(this); | |
| 835 } | |
| 836 | |
| 837 int bytesPerElement() { | |
| 838 return _BYTES_PER_ELEMENT; | |
| 839 } | |
| 840 | |
| 841 int lengthInBytes() { | |
| 842 return _length() * _BYTES_PER_ELEMENT; | |
| 843 } | |
| 844 | |
| 845 static final int _BYTES_PER_ELEMENT = 4; | |
| 846 | |
| 847 static _Float32Array _new(int length) native "Float32Array_new"; | |
| 848 | |
| 849 int _getIndexed(int index) native "Float32Array_getIndexed"; | |
| 850 | |
| 851 void _setIndexed(int index, double value) native "Float32Array_setIndexed"; | |
| 852 } | |
| 853 | |
| 854 | |
| 855 class _Float64Array extends _ByteArrayBase implements Float64Array { | |
| 856 factory _Float64Array(int length) { | |
| 857 return _new(length); | |
| 858 } | |
| 859 | |
| 860 factory _Float64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 861 if (length === null) { | |
| 862 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 863 } | |
| 864 return new _Float64ArrayView(array, start, length); | |
| 865 } | |
| 866 | |
| 867 double operator[](int index) { | |
| 868 return _getIndexed(index); | |
| 869 } | |
| 870 | |
| 871 void operator[]=(int index, double value) { | |
| 872 _setIndexed(index, value); | |
| 873 } | |
| 874 | |
| 875 Iterator<double> iterator() { | |
| 876 return new _ByteArrayIterator<double>(this); | |
| 877 } | |
| 878 | |
| 879 List<double> getRange(int start, int length) { | |
| 880 _rangeCheck(this, start, length); | |
| 881 _Float64Array result = _new(length); | |
| 882 result.setRange(0, length, this, start); | |
| 883 return result; | |
| 884 } | |
| 885 | |
| 886 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 887 if (from is _Float64Array) { | |
| 888 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 889 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 890 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 891 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 892 } else { | |
| 893 Arrays.copy(from, startFrom, this, start, length); | |
| 894 } | |
| 895 } | |
| 896 | |
| 897 String toString() { | |
| 898 return Collections.collectionToString(this); | |
| 899 } | |
| 900 | |
| 901 int bytesPerElement() { | |
| 902 return _BYTES_PER_ELEMENT; | |
| 903 } | |
| 904 | |
| 905 int lengthInBytes() { | |
| 906 return _length() * _BYTES_PER_ELEMENT; | |
| 907 } | |
| 908 | |
| 909 static final int _BYTES_PER_ELEMENT = 8; | |
| 910 | |
| 911 static _Float64Array _new(int length) native "Float64Array_new"; | |
| 912 | |
| 913 int _getIndexed(int index) native "Float64Array_getIndexed"; | |
| 914 | |
| 915 void _setIndexed(int index, double value) native "Float64Array_setIndexed"; | |
| 916 } | |
| 917 | |
| 918 | |
| 919 class _ExternalInt8Array extends _ByteArrayBase implements Int8Array { | |
| 920 int operator[](int index) { | |
| 921 return _getIndexed(index); | |
| 922 } | |
| 923 | |
| 924 int operator[]=(int index, int value) { | |
| 925 _setIndexed(index, _toInt8(value)); | |
| 926 } | |
| 927 | |
| 928 Iterator<int> iterator() { | |
| 929 return new _ByteArrayIterator<int>(this); | |
| 930 } | |
| 931 | |
| 932 _Int8Array getRange(int start, int length) { | |
| 933 _rangeCheck(this, start, length); | |
| 934 _Int8Array result = new Int8Array(length); | |
| 935 result.setRange(0, length, this, start); | |
| 936 return result; | |
| 937 } | |
| 938 | |
| 939 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 940 if (from is _ExternalInt8Array) { | |
| 941 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 942 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 943 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 944 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 945 } else { | |
| 946 Arrays.copy(from, startFrom, this, start, length); | |
| 947 } | |
| 948 } | |
| 949 | |
| 950 String toString() { | |
| 951 return Collections.collectionToString(this); | |
| 952 } | |
| 953 | |
| 954 int bytesPerElement() { | |
| 955 return _BYTES_PER_ELEMENT; | |
| 956 } | |
| 957 | |
| 958 int lengthInBytes() { | |
| 959 return _length() * _BYTES_PER_ELEMENT; | |
| 960 } | |
| 961 | |
| 962 static final int _BYTES_PER_ELEMENT = 1; | |
| 963 | |
| 964 int _getIndexed(int index) native "ExternalInt8Array_getIndexed"; | |
| 965 | |
| 966 void _setIndexed(int index, int value) native "ExternalInt8Array_setIndexed"; | |
| 967 } | |
| 968 | |
| 969 | |
| 970 class _ExternalUint8Array extends _ByteArrayBase implements Uint8Array { | |
| 971 int operator[](int index) { | |
| 972 return _getIndexed(index); | |
| 973 } | |
| 974 | |
| 975 int operator[]=(int index, int value) { | |
| 976 _setIndexed(index, _toUint8(value)); | |
| 977 } | |
| 978 | |
| 979 Iterator<int> iterator() { | |
| 980 return new _ByteArrayIterator<int>(this); | |
| 981 } | |
| 982 | |
| 983 _Uint8Array getRange(int start, int length) { | |
| 984 _rangeCheck(this, start, length); | |
| 985 _Uint8Array result = new Uint8Array(length); | |
| 986 result.setRange(0, length, this, start); | |
| 987 return result; | |
| 988 } | |
| 989 | |
| 990 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 991 if (from is _ExternalUint8Array) { | |
| 992 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 993 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 994 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 995 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 996 } else { | |
| 997 Arrays.copy(from, startFrom, this, start, length); | |
| 998 } | |
| 999 } | |
| 1000 | |
| 1001 String toString() { | |
| 1002 return Collections.collectionToString(this); | |
| 1003 } | |
| 1004 | |
| 1005 int bytesPerElement() { | |
| 1006 return _BYTES_PER_ELEMENT; | |
| 1007 } | |
| 1008 | |
| 1009 int lengthInBytes() { | |
| 1010 return _length() * _BYTES_PER_ELEMENT; | |
| 1011 } | |
| 1012 | |
| 1013 static final int _BYTES_PER_ELEMENT = 1; | |
| 1014 | |
| 1015 int _getIndexed(int index) native "ExternalUint8Array_getIndexed"; | |
| 1016 | |
| 1017 void _setIndexed(int index, int value) native "ExternalUint8Array_setIndexed"; | |
| 1018 } | |
| 1019 | |
| 1020 | |
| 1021 class _ExternalInt16Array extends _ByteArrayBase implements Int16Array { | |
| 1022 int operator[](int index) { | |
| 1023 return _getIndexed(index); | |
| 1024 } | |
| 1025 | |
| 1026 int operator[]=(int index, int value) { | |
| 1027 _setIndexed(index, _toInt16(value)); | |
| 1028 } | |
| 1029 | |
| 1030 Iterator<int> iterator() { | |
| 1031 return new _ByteArrayIterator<int>(this); | |
| 1032 } | |
| 1033 | |
| 1034 _Int16Array getRange(int start, int length) { | |
| 1035 _rangeCheck(this, start, length); | |
| 1036 _Int16Array result = new Int16Array(length); | |
| 1037 result.setRange(0, length, this, start); | |
| 1038 return result; | |
| 1039 } | |
| 1040 | |
| 1041 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1042 if (from is _ExternalInt16Array) { | |
| 1043 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1044 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1045 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1046 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1047 } else { | |
| 1048 Arrays.copy(from, startFrom, this, start, length); | |
| 1049 } | |
| 1050 } | |
| 1051 | |
| 1052 String toString() { | |
| 1053 return Collections.collectionToString(this); | |
| 1054 } | |
| 1055 | |
| 1056 int bytesPerElement() { | |
| 1057 return _BYTES_PER_ELEMENT; | |
| 1058 } | |
| 1059 | |
| 1060 int lengthInBytes() { | |
| 1061 return _length() * _BYTES_PER_ELEMENT; | |
| 1062 } | |
| 1063 | |
| 1064 static final int _BYTES_PER_ELEMENT = 2; | |
| 1065 | |
| 1066 int _getIndexed(int index) native "ExternalInt16Array_getIndexed"; | |
| 1067 | |
| 1068 void _setIndexed(int index, int value) native "ExternalInt16Array_setIndexed"; | |
| 1069 } | |
| 1070 | |
| 1071 | |
| 1072 class _ExternalUint16Array extends _ByteArrayBase implements Uint16Array { | |
| 1073 int operator[](int index) { | |
| 1074 return _getIndexed(index); | |
| 1075 } | |
| 1076 | |
| 1077 int operator[]=(int index, int value) { | |
| 1078 _setIndexed(index, _toUint16(value)); | |
| 1079 } | |
| 1080 | |
| 1081 Iterator<int> iterator() { | |
| 1082 return new _ByteArrayIterator<int>(this); | |
| 1083 } | |
| 1084 | |
| 1085 _Uint16Array getRange(int start, int length) { | |
| 1086 _rangeCheck(this, start, length); | |
| 1087 _Uint16Array result = new Uint16Array(length); | |
| 1088 result.setRange(0, length, this, start); | |
| 1089 return result; | |
| 1090 } | |
| 1091 | |
| 1092 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1093 if (from is _ExternalUint16Array) { | |
| 1094 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1095 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1096 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1097 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1098 } else { | |
| 1099 Arrays.copy(from, startFrom, this, start, length); | |
| 1100 } | |
| 1101 } | |
| 1102 | |
| 1103 String toString() { | |
| 1104 return Collections.collectionToString(this); | |
| 1105 } | |
| 1106 | |
| 1107 int bytesPerElement() { | |
| 1108 return _BYTES_PER_ELEMENT; | |
| 1109 } | |
| 1110 | |
| 1111 int lengthInBytes() { | |
| 1112 return _length() * _BYTES_PER_ELEMENT; | |
| 1113 } | |
| 1114 | |
| 1115 static final int _BYTES_PER_ELEMENT = 2; | |
| 1116 | |
| 1117 int _getIndexed(int index) native "ExternalUint16Array_getIndexed"; | |
| 1118 | |
| 1119 void _setIndexed(int index, int value) | |
| 1120 native "ExternalUint16Array_setIndexed"; | |
| 1121 } | |
| 1122 | |
| 1123 | |
| 1124 class _ExternalInt32Array extends _ByteArrayBase implements Int32Array { | |
| 1125 int operator[](int index) { | |
| 1126 return _getIndexed(index); | |
| 1127 } | |
| 1128 | |
| 1129 int operator[]=(int index, int value) { | |
| 1130 _setIndexed(index, _toInt32(value)); | |
| 1131 } | |
| 1132 | |
| 1133 Iterator<int> iterator() { | |
| 1134 return new _ByteArrayIterator<int>(this); | |
| 1135 } | |
| 1136 | |
| 1137 _Int32Array getRange(int start, int length) { | |
| 1138 _rangeCheck(this, start, length); | |
| 1139 _Int32Array result = new Int32Array(length); | |
| 1140 result.setRange(0, length, this, start); | |
| 1141 return result; | |
| 1142 } | |
| 1143 | |
| 1144 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1145 if (from is _ExternalInt32Array) { | |
| 1146 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1147 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1148 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1149 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1150 } else { | |
| 1151 Arrays.copy(from, startFrom, this, start, length); | |
| 1152 } | |
| 1153 } | |
| 1154 | |
| 1155 String toString() { | |
| 1156 return Collections.collectionToString(this); | |
| 1157 } | |
| 1158 | |
| 1159 int bytesPerElement() { | |
| 1160 return _BYTES_PER_ELEMENT; | |
| 1161 } | |
| 1162 | |
| 1163 int lengthInBytes() { | |
| 1164 return _length() * _BYTES_PER_ELEMENT; | |
| 1165 } | |
| 1166 | |
| 1167 static final int _BYTES_PER_ELEMENT = 4; | |
| 1168 | |
| 1169 int _getIndexed(int index) native "ExternalInt32Array_getIndexed"; | |
| 1170 | |
| 1171 void _setIndexed(int index, int value) native "ExternalInt32Array_setIndexed"; | |
| 1172 } | |
| 1173 | |
| 1174 | |
| 1175 class _ExternalUint32Array extends _ByteArrayBase implements Uint32Array { | |
| 1176 int operator[](int index) { | |
| 1177 return _getIndexed(index); | |
| 1178 } | |
| 1179 | |
| 1180 int operator[]=(int index, int value) { | |
| 1181 _setIndexed(index, _toUint32(value)); | |
| 1182 } | |
| 1183 | |
| 1184 Iterator<int> iterator() { | |
| 1185 return new _ByteArrayIterator<int>(this); | |
| 1186 } | |
| 1187 | |
| 1188 _Uint32Array getRange(int start, int length) { | |
| 1189 _rangeCheck(this, start, length); | |
| 1190 _Uint32Array result = new Uint32Array(length); | |
| 1191 result.setRange(0, length, this, start); | |
| 1192 return result; | |
| 1193 } | |
| 1194 | |
| 1195 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1196 if (from is _ExternalUint32Array) { | |
| 1197 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1198 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1199 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1200 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1201 } else { | |
| 1202 Arrays.copy(from, startFrom, this, start, length); | |
| 1203 } | |
| 1204 } | |
| 1205 | |
| 1206 String toString() { | |
| 1207 return Collections.collectionToString(this); | |
| 1208 } | |
| 1209 | |
| 1210 int bytesPerElement() { | |
| 1211 return _BYTES_PER_ELEMENT; | |
| 1212 } | |
| 1213 | |
| 1214 int lengthInBytes() { | |
| 1215 return _length() * _BYTES_PER_ELEMENT; | |
| 1216 } | |
| 1217 | |
| 1218 static final int _BYTES_PER_ELEMENT = 4; | |
| 1219 | |
| 1220 int _getIndexed(int index) native "ExternalUint32Array_getIndexed"; | |
| 1221 | |
| 1222 void _setIndexed(int index, int value) | |
| 1223 native "ExternalUint32Array_setIndexed"; | |
| 1224 } | |
| 1225 | |
| 1226 | |
| 1227 class _ExternalInt64Array extends _ByteArrayBase implements Int64Array { | |
| 1228 int operator[](int index) { | |
| 1229 return _getIndexed(index); | |
| 1230 } | |
| 1231 | |
| 1232 int operator[]=(int index, int value) { | |
| 1233 _setIndexed(index, _toInt64(value)); | |
| 1234 } | |
| 1235 | |
| 1236 Iterator<int> iterator() { | |
| 1237 return new _ByteArrayIterator<int>(this); | |
| 1238 } | |
| 1239 | |
| 1240 _Int64Array getRange(int start, int length) { | |
| 1241 _rangeCheck(this, start, length); | |
| 1242 _Int64Array result = new Int64Array(length); | |
| 1243 result.setRange(0, length, this, start); | |
| 1244 return result; | |
| 1245 } | |
| 1246 | |
| 1247 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1248 if (from is _ExternalInt64Array) { | |
| 1249 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1250 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1251 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1252 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1253 } else { | |
| 1254 Arrays.copy(from, startFrom, this, start, length); | |
| 1255 } | |
| 1256 } | |
| 1257 | |
| 1258 String toString() { | |
| 1259 return Collections.collectionToString(this); | |
| 1260 } | |
| 1261 | |
| 1262 int bytesPerElement() { | |
| 1263 return _BYTES_PER_ELEMENT; | |
| 1264 } | |
| 1265 | |
| 1266 int lengthInBytes() { | |
| 1267 return _length() * _BYTES_PER_ELEMENT; | |
| 1268 } | |
| 1269 | |
| 1270 static final int _BYTES_PER_ELEMENT = 8; | |
| 1271 | |
| 1272 int _getIndexed(int index) native "ExternalInt64Array_getIndexed"; | |
| 1273 | |
| 1274 void _setIndexed(int index, int value) native "ExternalInt64Array_setIndexed"; | |
| 1275 } | |
| 1276 | |
| 1277 | |
| 1278 class _ExternalUint64Array extends _ByteArrayBase implements Uint64Array { | |
| 1279 int operator[](int index) { | |
| 1280 return _getIndexed(index); | |
| 1281 } | |
| 1282 | |
| 1283 int operator[]=(int index, int value) { | |
| 1284 _setIndexed(index, _toUint64(value)); | |
| 1285 } | |
| 1286 | |
| 1287 Iterator<int> iterator() { | |
| 1288 return new _ByteArrayIterator<int>(this); | |
| 1289 } | |
| 1290 | |
| 1291 _Uint64Array getRange(int start, int length) { | |
| 1292 _rangeCheck(this, start, length); | |
| 1293 _Uint64Array result = new Uint64Array(length); | |
| 1294 result.setRange(0, length, this, start); | |
| 1295 return result; | |
| 1296 } | |
| 1297 | |
| 1298 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1299 if (from is _ExternalUint64Array) { | |
| 1300 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1301 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1302 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1303 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1304 } else { | |
| 1305 Arrays.copy(from, startFrom, this, start, length); | |
| 1306 } | |
| 1307 } | |
| 1308 | |
| 1309 String toString() { | |
| 1310 return Collections.collectionToString(this); | |
| 1311 } | |
| 1312 | |
| 1313 int bytesPerElement() { | |
| 1314 return _BYTES_PER_ELEMENT; | |
| 1315 } | |
| 1316 | |
| 1317 int lengthInBytes() { | |
| 1318 return _length() * _BYTES_PER_ELEMENT; | |
| 1319 } | |
| 1320 | |
| 1321 static final int _BYTES_PER_ELEMENT = 8; | |
| 1322 | |
| 1323 int _getIndexed(int index) native "ExternalUint64Array_getIndexed"; | |
| 1324 | |
| 1325 void _setIndexed(int index, int value) | |
| 1326 native "ExternalUint64Array_setIndexed"; | |
| 1327 } | |
| 1328 | |
| 1329 | |
| 1330 class _ExternalFloat32Array extends _ByteArrayBase implements Float32Array { | |
| 1331 int operator[](int index) { | |
| 1332 return _getIndexed(index); | |
| 1333 } | |
| 1334 | |
| 1335 int operator[]=(int index, double value) { | |
| 1336 _setIndexed(index, value); | |
| 1337 } | |
| 1338 | |
| 1339 Iterator<int> iterator() { | |
| 1340 return new _ByteArrayIterator<double>(this); | |
| 1341 } | |
| 1342 | |
| 1343 _Float32Array getRange(int start, int length) { | |
| 1344 _rangeCheck(this, start, length); | |
| 1345 _Float32Array result = new Float32Array(length); | |
| 1346 result.setRange(0, length, this, start); | |
| 1347 return result; | |
| 1348 } | |
| 1349 | |
| 1350 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 1351 if (from is _ExternalFloat32Array) { | |
| 1352 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1353 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1354 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1355 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1356 } else { | |
| 1357 Arrays.copy(from, startFrom, this, start, length); | |
| 1358 } | |
| 1359 } | |
| 1360 | |
| 1361 String toString() { | |
| 1362 return Collections.collectionToString(this); | |
| 1363 } | |
| 1364 | |
| 1365 int bytesPerElement() { | |
| 1366 return _BYTES_PER_ELEMENT; | |
| 1367 } | |
| 1368 | |
| 1369 int lengthInBytes() { | |
| 1370 return _length() * _BYTES_PER_ELEMENT; | |
| 1371 } | |
| 1372 | |
| 1373 static final int _BYTES_PER_ELEMENT = 4; | |
| 1374 | |
| 1375 int _getIndexed(int index) native "ExternalFloat32Array_getIndexed"; | |
| 1376 | |
| 1377 void _setIndexed(int index, int value) | |
| 1378 native "ExternalFloat32Array_setIndexed"; | |
| 1379 } | |
| 1380 | |
| 1381 | |
| 1382 class _ExternalFloat64Array extends _ByteArrayBase implements Float64Array { | |
| 1383 int operator[](int index) { | |
| 1384 return _getIndexed(index); | |
| 1385 } | |
| 1386 | |
| 1387 int operator[]=(int index, double value) { | |
| 1388 _setIndexed(index, value); | |
| 1389 } | |
| 1390 | |
| 1391 Iterator<int> iterator() { | |
| 1392 return new _ByteArrayIterator<double>(this); | |
| 1393 } | |
| 1394 | |
| 1395 _Float64Array getRange(int start, int length) { | |
| 1396 _rangeCheck(this, start, length); | |
| 1397 _Float64Array result = new Float64Array(length); | |
| 1398 result.setRange(0, length, this, start); | |
| 1399 return result; | |
| 1400 } | |
| 1401 | |
| 1402 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 1403 if (from is _ExternalFloat64Array) { | |
| 1404 int startInBytes = start * _BYTES_PER_ELEMENT; | |
| 1405 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1406 int startFromInBytes = startFrom * _BYTES_PER_ELEMENT; | |
| 1407 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1408 } else { | |
| 1409 Arrays.copy(from, startFrom, this, start, length); | |
| 1410 } | |
| 1411 } | |
| 1412 | |
| 1413 String toString() { | |
| 1414 return Collections.collectionToString(this); | |
| 1415 } | |
| 1416 | |
| 1417 int bytesPerElement() { | |
| 1418 return _BYTES_PER_ELEMENT; | |
| 1419 } | |
| 1420 | |
| 1421 int lengthInBytes() { | |
| 1422 return _length() * _BYTES_PER_ELEMENT; | |
| 1423 } | |
| 1424 | |
| 1425 static final int _BYTES_PER_ELEMENT = 8; | |
| 1426 | |
| 1427 int _getIndexed(int index) native "ExternalFloat64Array_getIndexed"; | |
| 1428 | |
| 1429 void _setIndexed(int index, int value) | |
| 1430 native "ExternalFloat64Array_setIndexed"; | |
| 1431 } | |
| 1432 | |
| 1433 | |
| 1434 class _ByteArrayIterator<E> implements Iterator<E> { | |
| 1435 _ByteArrayIterator(_ByteArrayBase array) | |
| 1436 : _array = array, _length = array.length, _pos = 0; | |
| 1437 | 223 |
| 1438 bool hasNext() { | 224 bool hasNext() { |
| 1439 return _length > _pos; | 225 return _length > _pos; |
| 1440 } | 226 } |
| 1441 | 227 |
| 1442 E next() { | 228 int next() { |
| 1443 if (!hasNext()) { | 229 if (!hasNext()) { |
| 1444 throw const NoMoreElementsException(); | 230 throw const NoMoreElementsException(); |
| 1445 } | 231 } |
| 1446 return _array[_pos++]; | 232 return _byteArray[_pos++]; |
| 1447 } | 233 } |
| 1448 | 234 |
| 1449 final List<E> _array; | 235 final List _byteArray; |
| 1450 | 236 |
| 1451 final int _length; | 237 final int _length; |
| 1452 | 238 |
| 1453 int _pos; | 239 int _pos; |
| 1454 } | 240 } |
| 1455 | 241 |
| 1456 | 242 |
| 1457 class _ByteArrayView implements ByteArray { | 243 class _InternalByteArray extends _ByteArrayBase implements ByteArray { |
| 1458 _ByteArrayView(this._array, this._offset, this._length) { | 244 factory _InternalByteArray(int length) { |
| 1459 } | 245 return _allocate(length); |
| 1460 | 246 } |
| 1461 int lengthInBytes() { | 247 |
| 1462 return _length; | 248 // ByteArray interface |
| 1463 } | |
| 1464 | |
| 1465 ByteArray subByteArray([int start = 0, int length]) { | |
| 1466 if (length === null) { | |
| 1467 length = this.lengthInBytes(); | |
| 1468 } | |
| 1469 _rangeCheck(start, length); | |
| 1470 return new _ByteArrayView(_array, _offset + start, length); | |
| 1471 } | |
| 1472 | 249 |
| 1473 int getInt8(int byteOffset) { | 250 int getInt8(int byteOffset) { |
| 1474 return _array._getInt8(_offset + byteOffset); | 251 return _getInt8(byteOffset); |
| 1475 } | 252 } |
| 253 |
| 1476 void setInt8(int byteOffset, int value) { | 254 void setInt8(int byteOffset, int value) { |
| 1477 _array._setInt8(_offset + byteOffset, value); | 255 _setInt8(byteOffset, _toInt8(value)); |
| 1478 } | 256 } |
| 1479 | 257 |
| 1480 int getUint8(int byteOffset) { | 258 int getUint8(int byteOffset) { |
| 1481 return _array._getUint8(_offset + byteOffset); | 259 return _getUint8(byteOffset); |
| 1482 } | 260 } |
| 261 |
| 1483 void setUint8(int byteOffset, int value) { | 262 void setUint8(int byteOffset, int value) { |
| 1484 _array._setUint8(_offset + byteOffset, value); | 263 _setUint8(byteOffset, _toUint8(value)); |
| 1485 } | 264 } |
| 1486 | 265 |
| 1487 int getInt16(int byteOffset) { | 266 int getInt16(int byteOffset) { |
| 1488 return _array._getInt16(_offset + byteOffset); | 267 return _getInt16(byteOffset); |
| 1489 } | 268 } |
| 269 |
| 1490 void setInt16(int byteOffset, int value) { | 270 void setInt16(int byteOffset, int value) { |
| 1491 _array._setInt16(_offset + byteOffset, value); | 271 _setInt16(byteOffset, _toInt16(value)); |
| 1492 } | 272 } |
| 1493 | 273 |
| 1494 int getUint16(int byteOffset) { | 274 int getUint16(int byteOffset) { |
| 1495 return _array._getUint16(_offset + byteOffset); | 275 return _getInt16(byteOffset); |
| 1496 } | 276 } |
| 277 |
| 1497 void setUint16(int byteOffset, int value) { | 278 void setUint16(int byteOffset, int value) { |
| 1498 _array._setUint16(_offset + byteOffset, value); | 279 _setUint16(byteOffset, _toUint16(value)); |
| 1499 } | 280 } |
| 1500 | 281 |
| 1501 int getInt32(int byteOffset) { | 282 int getInt32(int byteOffset) { |
| 1502 return _array._getInt32(_offset + byteOffset); | 283 return _getInt32(byteOffset); |
| 1503 } | 284 } |
| 285 |
| 1504 void setInt32(int byteOffset, int value) { | 286 void setInt32(int byteOffset, int value) { |
| 1505 _array._setInt32(_offset + byteOffset, value); | 287 _setInt32(byteOffset, _toInt32(value)); |
| 1506 } | 288 } |
| 1507 | 289 |
| 1508 int getUint32(int byteOffset) { | 290 int getUint32(int byteOffset) { |
| 1509 return _array._getUint32(_offset + byteOffset); | 291 return _getUint32(byteOffset); |
| 1510 } | 292 } |
| 293 |
| 1511 void setUint32(int byteOffset, int value) { | 294 void setUint32(int byteOffset, int value) { |
| 1512 _array._setUint32(_offset + byteOffset, value); | 295 _setUint32(byteOffset, _toUint32(value)); |
| 1513 } | 296 } |
| 1514 | 297 |
| 1515 int getInt64(int byteOffset) { | 298 int getInt64(int byteOffset) { |
| 1516 return _array._getInt64(_offset + byteOffset); | 299 return _getInt64(byteOffset); |
| 1517 } | 300 } |
| 301 |
| 1518 void setInt64(int byteOffset, int value) { | 302 void setInt64(int byteOffset, int value) { |
| 1519 _array._setInt64(_offset + byteOffset, value); | 303 _setInt64(byteOffset, _toInt64(value)); |
| 1520 } | 304 } |
| 1521 | 305 |
| 1522 int getUint64(int byteOffset) { | 306 int getUint64(int byteOffset) { |
| 1523 return _array._getUint64(_offset + byteOffset); | 307 return _getUint64(byteOffset); |
| 1524 } | 308 } |
| 309 |
| 1525 void setUint64(int byteOffset, int value) { | 310 void setUint64(int byteOffset, int value) { |
| 1526 _array._setUint64(_offset + byteOffset, value); | 311 _setUint64(byteOffset, _toUint64(value)); |
| 1527 } | 312 } |
| 1528 | 313 |
| 1529 double getFloat32(int byteOffset) { | 314 double getFloat32(int byteOffset) { |
| 1530 return _array._getFloat32(_offset + byteOffset); | 315 return _getFloat32(byteOffset); |
| 1531 } | 316 } |
| 317 |
| 1532 void setFloat32(int byteOffset, double value) { | 318 void setFloat32(int byteOffset, double value) { |
| 1533 _array._setFloat32(_offset + byteOffset, value); | 319 _setFloat32(byteOffset, value); |
| 1534 } | 320 } |
| 1535 | 321 |
| 1536 double getFloat64(int byteOffset) { | 322 double getFloat64(int byteOffset) { |
| 1537 return _array._getFloat64(_offset + byteOffset); | 323 return _getFloat64(byteOffset); |
| 1538 } | 324 } |
| 325 |
| 1539 void setFloat64(int byteOffset, double value) { | 326 void setFloat64(int byteOffset, double value) { |
| 1540 _array._setFloat64(_offset + byteOffset, value); | 327 _setFloat64(byteOffset, value); |
| 1541 } | 328 } |
| 1542 | 329 |
| 1543 final _ByteArrayBase _array; | 330 // Implementation |
| 1544 final int _offset; | 331 |
| 1545 final int _length; | 332 static _InternalByteArray _allocate(int length) |
| 333 native "InternalByteArray_allocate"; |
| 334 |
| 335 int _getInt8(int byteOffset) |
| 336 native "InternalByteArray_getInt8"; |
| 337 |
| 338 void _setInt8(int byteOffset, int value) |
| 339 native "InternalByteArray_setInt8"; |
| 340 |
| 341 int _getUint8(int byteOffset) |
| 342 native "InternalByteArray_getUint8"; |
| 343 |
| 344 void _setUint8(int byteOffset, int value) |
| 345 native "InternalByteArray_setUint8"; |
| 346 |
| 347 int _getInt16(int byteOffset) |
| 348 native "InternalByteArray_getInt16"; |
| 349 |
| 350 void _setInt16(int byteOffset, int value) |
| 351 native "InternalByteArray_setInt16"; |
| 352 |
| 353 int _getUint16(int byteOffset) |
| 354 native "InternalByteArray_getUint16"; |
| 355 |
| 356 void _setUint16(int byteOffset, int value) |
| 357 native "InternalByteArray_setUint16"; |
| 358 |
| 359 int _getInt32(int byteOffset) |
| 360 native "InternalByteArray_getInt32"; |
| 361 |
| 362 void _setInt32(int byteOffset, int value) |
| 363 native "InternalByteArray_setInt32"; |
| 364 |
| 365 int _getUint32(int byteOffset) |
| 366 native "InternalByteArray_getUint32"; |
| 367 |
| 368 void _setUint32(int byteOffset, int value) |
| 369 native "InternalByteArray_setUint32"; |
| 370 |
| 371 int _getInt64(int byteOffset) |
| 372 native "InternalByteArray_getInt64"; |
| 373 |
| 374 void _setInt64(int byteOffset, int value) |
| 375 native "InternalByteArray_setInt64"; |
| 376 |
| 377 int _getUint64(int byteOffset) |
| 378 native "InternalByteArray_getUint64"; |
| 379 |
| 380 void _setUint64(int byteOffset, int value) |
| 381 native "InternalByteArray_setUint64"; |
| 382 |
| 383 double _getFloat32(int byteOffset) |
| 384 native "InternalByteArray_getFloat32"; |
| 385 |
| 386 void _setFloat32(int byteOffset, double value) |
| 387 native "InternalByteArray_setFloat32"; |
| 388 |
| 389 double _getFloat64(int byteOffset) |
| 390 native "InternalByteArray_getFloat64"; |
| 391 |
| 392 void _setFloat64(int byteOffset, double value) |
| 393 native "InternalByteArray_setFloat64"; |
| 1546 } | 394 } |
| 1547 | 395 |
| 1548 | 396 |
| 1549 class _ByteArrayViewBase { | 397 class _ExternalByteArray extends _ByteArrayBase implements ByteArray { |
| 1550 void add(value) { | 398 // Collection interface |
| 1551 throw const UnsupportedOperationException( | 399 |
| 1552 "Cannot add to a non-extendable array"); | 400 int get length() { |
| 1553 } | 401 return _length(); |
| 1554 | 402 } |
| 1555 void addLast(value) { | 403 |
| 1556 throw const UnsupportedOperationException( | 404 // List interface |
| 1557 "Cannot add to a non-extendable array"); | 405 |
| 1558 } | 406 int operator[](int index) { |
| 1559 | 407 return _getUint8(index); |
| 1560 void addAll(Collection value) { | 408 } |
| 1561 throw const UnsupportedOperationException( | 409 |
| 1562 "Cannot add to a non-extendable array"); | 410 void operator[]=(int index, int value) { |
| 1563 } | 411 _setUint8(index, value); |
| 1564 | 412 } |
| 1565 void clear() { | 413 |
| 1566 throw const UnsupportedOperationException( | 414 // ByteArray interface |
| 1567 "Cannot remove from a non-extendable array"); | 415 |
| 1568 } | 416 int getInt8(int byteOffset) { |
| 1569 | 417 return _getInt8(byteOffset); |
| 1570 void insertRange(int start, int length, [initialValue]) { | 418 } |
| 1571 throw const UnsupportedOperationException( | 419 |
| 1572 "Cannot add to a non-extendable array"); | 420 void setInt8(int byteOffset, int value) { |
| 1573 } | 421 _setInt8(byteOffset, _toInt8(value)); |
| 1574 | 422 } |
| 1575 set length(int newLength) { | 423 |
| 1576 throw const UnsupportedOperationException( | 424 int getUint8(int byteOffset) { |
| 1577 "Cannot resize a non-extendable array"); | 425 return _getUint8(byteOffset); |
| 1578 } | 426 } |
| 1579 | 427 |
| 1580 int removeLast() { | 428 void setUint8(int byteOffset, int value) { |
| 1581 throw const UnsupportedOperationException( | 429 _setUint8(byteOffset, _toUint8(value)); |
| 1582 "Cannot remove from a non-extendable array"); | 430 } |
| 1583 } | 431 |
| 1584 | 432 int getInt16(int byteOffset) { |
| 1585 void removeRange(int start, int length) { | 433 return _getInt16(byteOffset); |
| 1586 throw const UnsupportedOperationException( | 434 } |
| 1587 "Cannot remove from a non-extendable array"); | 435 |
| 1588 } | 436 void setInt16(int byteOffset, int value) { |
| 437 _setInt16(byteOffset, _toInt16(value)); |
| 438 } |
| 439 |
| 440 int getUint16(int byteOffset) { |
| 441 return _getInt16(byteOffset); |
| 442 } |
| 443 |
| 444 void setUint16(int byteOffset, int value) { |
| 445 _setUint16(byteOffset, _toUint16(value)); |
| 446 } |
| 447 |
| 448 int getInt32(int byteOffset) { |
| 449 return _getInt32(byteOffset); |
| 450 } |
| 451 |
| 452 void setInt32(int byteOffset, int value) { |
| 453 _setInt32(byteOffset, _toInt32(value)); |
| 454 } |
| 455 |
| 456 int getUint32(int byteOffset) { |
| 457 return _getUint32(byteOffset); |
| 458 } |
| 459 |
| 460 void setUint32(int byteOffset, int value) { |
| 461 _setUint32(byteOffset, _toUint32(value)); |
| 462 } |
| 463 |
| 464 int getInt64(int byteOffset) { |
| 465 return _getInt64(byteOffset); |
| 466 } |
| 467 |
| 468 void setInt64(int byteOffset, int value) { |
| 469 _setInt64(byteOffset, _toInt64(value)); |
| 470 } |
| 471 |
| 472 int getUint64(int byteOffset) { |
| 473 return _getUint64(byteOffset); |
| 474 } |
| 475 |
| 476 void setUint64(int byteOffset, int value) { |
| 477 _setUint64(byteOffset, _toUint64(value)); |
| 478 } |
| 479 |
| 480 double getFloat32(int byteOffset) { |
| 481 return _getFloat32(byteOffset); |
| 482 } |
| 483 |
| 484 void setFloat32(int byteOffset, double value) { |
| 485 _setFloat32(byteOffset, value); |
| 486 } |
| 487 |
| 488 double getFloat64(int byteOffset) { |
| 489 return _getFloat64(byteOffset); |
| 490 } |
| 491 |
| 492 void setFloat64(int byteOffset, double value) { |
| 493 _setFloat64(byteOffset, value); |
| 494 } |
| 495 |
| 496 // Implementation |
| 497 |
| 498 int _getInt8(int byteOffset) |
| 499 native "ExternalByteArray_getInt8"; |
| 500 |
| 501 void _setInt8(int byteOffset, int value) |
| 502 native "ExternalByteArray_setInt8"; |
| 503 |
| 504 int _getUint8(int byteOffset) |
| 505 native "ExternalByteArray_getUint8"; |
| 506 |
| 507 void _setUint8(int byteOffset, int value) |
| 508 native "ExternalByteArray_setUint8"; |
| 509 |
| 510 int _getInt16(int byteOffset) |
| 511 native "ExternalByteArray_getInt16"; |
| 512 |
| 513 void _setInt16(int byteOffset, int value) |
| 514 native "ExternalByteArray_setInt16"; |
| 515 |
| 516 int _getUint16(int byteOffset) |
| 517 native "ExternalByteArray_getUint16"; |
| 518 |
| 519 void _setUint16(int byteOffset, int value) |
| 520 native "ExternalByteArray_setUint16"; |
| 521 |
| 522 int _getInt32(int byteOffset) |
| 523 native "ExternalByteArray_getInt32"; |
| 524 |
| 525 void _setInt32(int byteOffset, int value) |
| 526 native "ExternalByteArray_setInt32"; |
| 527 |
| 528 int _getUint32(int byteOffset) |
| 529 native "ExternalByteArray_getUint32"; |
| 530 |
| 531 void _setUint32(int byteOffset, int value) |
| 532 native "ExternalByteArray_setUint32"; |
| 533 |
| 534 int _getInt64(int byteOffset) |
| 535 native "ExternalByteArray_getInt64"; |
| 536 |
| 537 void _setInt64(int byteOffset, int value) |
| 538 native "ExternalByteArray_setInt64"; |
| 539 |
| 540 int _getUint64(int byteOffset) |
| 541 native "ExternalByteArray_getUint64"; |
| 542 |
| 543 void _setUint64(int byteOffset, int value) |
| 544 native "ExternalByteArray_setUint64"; |
| 545 |
| 546 double _getFloat32(int byteOffset) |
| 547 native "ExternalByteArray_getFloat32"; |
| 548 |
| 549 void _setFloat32(int byteOffset, double value) |
| 550 native "ExternalByteArray_setFloat32"; |
| 551 |
| 552 double _getFloat64(int byteOffset) |
| 553 native "ExternalByteArray_getFloat64"; |
| 554 |
| 555 void _setFloat64(int byteOffset, double value) |
| 556 native "ExternalByteArray_setFloat64"; |
| 1589 } | 557 } |
| 1590 | |
| 1591 | |
| 1592 class _Int8ArrayView extends _ByteArrayViewBase implements Int8Array { | |
| 1593 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1594 : _array = array, | |
| 1595 _offset = offsetInBytes, | |
| 1596 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 1597 : length { | |
| 1598 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1599 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1600 } | |
| 1601 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1602 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1603 throw new IndexOutOfRangeException(length); | |
| 1604 } | |
| 1605 } | |
| 1606 | |
| 1607 get length() { | |
| 1608 return _length; | |
| 1609 } | |
| 1610 | |
| 1611 int operator[](int index) { | |
| 1612 if (index < 0 || index >= _length) { | |
| 1613 throw new IndexOutOfRangeException(index); | |
| 1614 } | |
| 1615 return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 1616 } | |
| 1617 | |
| 1618 void operator[]=(int index, int value) { | |
| 1619 if (index < 0 || index >= _length) { | |
| 1620 throw new IndexOutOfRangeException(index); | |
| 1621 } | |
| 1622 _array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value)); | |
| 1623 } | |
| 1624 | |
| 1625 Iterator<int> iterator() { | |
| 1626 return new _ByteArrayIterator<int>(this); | |
| 1627 } | |
| 1628 | |
| 1629 List<int> getRange(int start, int length) { | |
| 1630 _rangeCheck(this, start, length); | |
| 1631 Int8Array result = new Int8Array(length); | |
| 1632 result.setRange(0, length, this, start); | |
| 1633 return result; | |
| 1634 } | |
| 1635 | |
| 1636 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1637 Arrays.copy(from, startFrom, this, start, length); | |
| 1638 } | |
| 1639 | |
| 1640 String toString() { | |
| 1641 return Collections.collectionToString(this); | |
| 1642 } | |
| 1643 | |
| 1644 int bytesPerElement() { | |
| 1645 return _BYTES_PER_ELEMENT; | |
| 1646 } | |
| 1647 | |
| 1648 int lengthInBytes() { | |
| 1649 return _length * _BYTES_PER_ELEMENT; | |
| 1650 } | |
| 1651 | |
| 1652 ByteArray asByteArray([int start = 0, int length]) { | |
| 1653 if (length == null) { | |
| 1654 length = this.lengthInBytes(); | |
| 1655 } | |
| 1656 _rangeCheck(start, length); | |
| 1657 return _array.subByteArray(_offset + start, length); | |
| 1658 } | |
| 1659 | |
| 1660 static final int _BYTES_PER_ELEMENT = 1; | |
| 1661 final ByteArray _array; | |
| 1662 final int _offset; | |
| 1663 final int _length; | |
| 1664 } | |
| 1665 | |
| 1666 | |
| 1667 class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8Array { | |
| 1668 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1669 : _array = array, | |
| 1670 _offset = offsetInBytes, | |
| 1671 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 1672 : length { | |
| 1673 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1674 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1675 } | |
| 1676 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1677 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1678 throw new IndexOutOfRangeException(length); | |
| 1679 } | |
| 1680 } | |
| 1681 | |
| 1682 get length() { | |
| 1683 return _length; | |
| 1684 } | |
| 1685 | |
| 1686 int operator[](int index) { | |
| 1687 if (index < 0 || index >= _length) { | |
| 1688 throw new IndexOutOfRangeException(index); | |
| 1689 } | |
| 1690 return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 1691 } | |
| 1692 | |
| 1693 void operator[]=(int index, int value) { | |
| 1694 if (index < 0 || index >= _length) { | |
| 1695 throw new IndexOutOfRangeException(index); | |
| 1696 } | |
| 1697 _array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value)); | |
| 1698 } | |
| 1699 | |
| 1700 Iterator<int> iterator() { | |
| 1701 return new _ByteArrayIterator<int>(this); | |
| 1702 } | |
| 1703 | |
| 1704 List<int> getRange(int start, int length) { | |
| 1705 _rangeCheck(this, start, length); | |
| 1706 Uint8Array result = new Uint8Array(length); | |
| 1707 result.setRange(0, length, this, start); | |
| 1708 return result; | |
| 1709 } | |
| 1710 | |
| 1711 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1712 Arrays.copy(from, startFrom, this, start, length); | |
| 1713 } | |
| 1714 | |
| 1715 String toString() { | |
| 1716 return Collections.collectionToString(this); | |
| 1717 } | |
| 1718 | |
| 1719 int bytesPerElement() { | |
| 1720 return _BYTES_PER_ELEMENT; | |
| 1721 } | |
| 1722 | |
| 1723 int lengthInBytes() { | |
| 1724 return _length * _BYTES_PER_ELEMENT; | |
| 1725 } | |
| 1726 | |
| 1727 ByteArray asByteArray([int start = 0, int length]) { | |
| 1728 if (length == null) { | |
| 1729 length = this.lengthInBytes(); | |
| 1730 } | |
| 1731 _rangeCheck(start, length); | |
| 1732 return _array.subByteArray(_offset + start, length); | |
| 1733 } | |
| 1734 | |
| 1735 static final int _BYTES_PER_ELEMENT = 1; | |
| 1736 final ByteArray _array; | |
| 1737 final int _offset; | |
| 1738 final int _length; | |
| 1739 } | |
| 1740 | |
| 1741 | |
| 1742 class _Int16ArrayView extends _ByteArrayViewBase implements Int16Array { | |
| 1743 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1744 : _array = array, | |
| 1745 _offset = offsetInBytes, | |
| 1746 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 1747 : length { | |
| 1748 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1749 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1750 } | |
| 1751 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1752 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1753 throw new IndexOutOfRangeException(length); | |
| 1754 } | |
| 1755 } | |
| 1756 | |
| 1757 get length() { | |
| 1758 return _length; | |
| 1759 } | |
| 1760 | |
| 1761 int operator[](int index) { | |
| 1762 if (index < 0 || index >= _length) { | |
| 1763 throw new IndexOutOfRangeException(index); | |
| 1764 } | |
| 1765 return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 1766 } | |
| 1767 | |
| 1768 void operator[]=(int index, int value) { | |
| 1769 if (index < 0 || index >= _length) { | |
| 1770 throw new IndexOutOfRangeException(index); | |
| 1771 } | |
| 1772 _array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value)); | |
| 1773 } | |
| 1774 | |
| 1775 Iterator<int> iterator() { | |
| 1776 return new _ByteArrayIterator<int>(this); | |
| 1777 } | |
| 1778 | |
| 1779 List<int> getRange(int start, int length) { | |
| 1780 _rangeCheck(this, start, length); | |
| 1781 Int16Array result = new Int16Array(length); | |
| 1782 result.setRange(0, length, this, start); | |
| 1783 return result; | |
| 1784 } | |
| 1785 | |
| 1786 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1787 Arrays.copy(from, startFrom, this, start, length); | |
| 1788 } | |
| 1789 | |
| 1790 String toString() { | |
| 1791 return Collections.collectionToString(this); | |
| 1792 } | |
| 1793 | |
| 1794 int bytesPerElement() { | |
| 1795 return _BYTES_PER_ELEMENT; | |
| 1796 } | |
| 1797 | |
| 1798 int lengthInBytes() { | |
| 1799 return _length * _BYTES_PER_ELEMENT; | |
| 1800 } | |
| 1801 | |
| 1802 ByteArray asByteArray([int start = 0, int length]) { | |
| 1803 if (length == null) { | |
| 1804 length = this.lengthInBytes(); | |
| 1805 } | |
| 1806 _rangeCheck(start, length); | |
| 1807 return _array.subByteArray(_offset + start, length); | |
| 1808 } | |
| 1809 | |
| 1810 static final int _BYTES_PER_ELEMENT = 2; | |
| 1811 final ByteArray _array; | |
| 1812 final int _offset; | |
| 1813 final int _length; | |
| 1814 } | |
| 1815 | |
| 1816 | |
| 1817 class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16Array { | |
| 1818 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1819 : _array = array, | |
| 1820 _offset = offsetInBytes, | |
| 1821 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 1822 : length { | |
| 1823 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1824 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1825 } | |
| 1826 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1827 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1828 throw new IndexOutOfRangeException(length); | |
| 1829 } | |
| 1830 } | |
| 1831 | |
| 1832 get length() { | |
| 1833 return _length; | |
| 1834 } | |
| 1835 | |
| 1836 int operator[](int index) { | |
| 1837 if (index < 0 || index >= _length) { | |
| 1838 throw new IndexOutOfRangeException(index); | |
| 1839 } | |
| 1840 return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 1841 } | |
| 1842 | |
| 1843 void operator[]=(int index, int value) { | |
| 1844 if (index < 0 || index >= _length) { | |
| 1845 throw new IndexOutOfRangeException(index); | |
| 1846 } | |
| 1847 _array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value)); | |
| 1848 } | |
| 1849 | |
| 1850 Iterator<int> iterator() { | |
| 1851 return new _ByteArrayIterator<int>(this); | |
| 1852 } | |
| 1853 | |
| 1854 List<int> getRange(int start, int length) { | |
| 1855 _rangeCheck(this, start, length); | |
| 1856 Uint16Array result = new Uint16Array(length); | |
| 1857 result.setRange(0, length, this, start); | |
| 1858 return result; | |
| 1859 } | |
| 1860 | |
| 1861 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1862 Arrays.copy(from, startFrom, this, start, length); | |
| 1863 } | |
| 1864 | |
| 1865 String toString() { | |
| 1866 return Collections.collectionToString(this); | |
| 1867 } | |
| 1868 | |
| 1869 int bytesPerElement() { | |
| 1870 return _BYTES_PER_ELEMENT; | |
| 1871 } | |
| 1872 | |
| 1873 int lengthInBytes() { | |
| 1874 return _length * _BYTES_PER_ELEMENT; | |
| 1875 } | |
| 1876 | |
| 1877 ByteArray asByteArray([int start = 0, int length]) { | |
| 1878 if (length == null) { | |
| 1879 length = this.lengthInBytes(); | |
| 1880 } | |
| 1881 _rangeCheck(start, length); | |
| 1882 return _array.subByteArray(_offset + start, length); | |
| 1883 } | |
| 1884 | |
| 1885 static final int _BYTES_PER_ELEMENT = 2; | |
| 1886 final ByteArray _array; | |
| 1887 final int _offset; | |
| 1888 final int _length; | |
| 1889 } | |
| 1890 | |
| 1891 | |
| 1892 class _Int32ArrayView extends _ByteArrayViewBase implements Int32Array { | |
| 1893 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1894 : _array = array, | |
| 1895 _offset = offsetInBytes, | |
| 1896 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 1897 : length { | |
| 1898 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1899 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1900 } | |
| 1901 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1902 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1903 throw new IndexOutOfRangeException(length); | |
| 1904 } | |
| 1905 } | |
| 1906 | |
| 1907 get length() { | |
| 1908 return _length; | |
| 1909 } | |
| 1910 | |
| 1911 int operator[](int index) { | |
| 1912 if (index < 0 || index >= _length) { | |
| 1913 throw new IndexOutOfRangeException(index); | |
| 1914 } | |
| 1915 return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 1916 } | |
| 1917 | |
| 1918 void operator[]=(int index, int value) { | |
| 1919 if (index < 0 || index >= _length) { | |
| 1920 throw new IndexOutOfRangeException(index); | |
| 1921 } | |
| 1922 _array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value)); | |
| 1923 } | |
| 1924 | |
| 1925 Iterator<int> iterator() { | |
| 1926 return new _ByteArrayIterator<int>(this); | |
| 1927 } | |
| 1928 | |
| 1929 List<int> getRange(int start, int length) { | |
| 1930 _rangeCheck(this, start, length); | |
| 1931 Int32Array result = new Int32Array(length); | |
| 1932 result.setRange(0, length, this, start); | |
| 1933 return result; | |
| 1934 } | |
| 1935 | |
| 1936 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1937 Arrays.copy(from, startFrom, this, start, length); | |
| 1938 } | |
| 1939 | |
| 1940 String toString() { | |
| 1941 return Collections.collectionToString(this); | |
| 1942 } | |
| 1943 | |
| 1944 int bytesPerElement() { | |
| 1945 return _BYTES_PER_ELEMENT; | |
| 1946 } | |
| 1947 | |
| 1948 int lengthInBytes() { | |
| 1949 return _length * _BYTES_PER_ELEMENT; | |
| 1950 } | |
| 1951 | |
| 1952 ByteArray asByteArray([int start = 0, int length]) { | |
| 1953 if (length == null) { | |
| 1954 length = this.lengthInBytes(); | |
| 1955 } | |
| 1956 _rangeCheck(start, length); | |
| 1957 return _array.subByteArray(_offset + start, length); | |
| 1958 } | |
| 1959 | |
| 1960 static final int _BYTES_PER_ELEMENT = 4; | |
| 1961 final ByteArray _array; | |
| 1962 final int _offset; | |
| 1963 final int _length; | |
| 1964 } | |
| 1965 | |
| 1966 | |
| 1967 class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32Array { | |
| 1968 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1969 : _array = array, | |
| 1970 _offset = offsetInBytes, | |
| 1971 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 1972 : length { | |
| 1973 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1974 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1975 } | |
| 1976 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 1977 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1978 throw new IndexOutOfRangeException(length); | |
| 1979 } | |
| 1980 } | |
| 1981 | |
| 1982 get length() { | |
| 1983 return _length; | |
| 1984 } | |
| 1985 | |
| 1986 int operator[](int index) { | |
| 1987 if (index < 0 || index >= _length) { | |
| 1988 throw new IndexOutOfRangeException(index); | |
| 1989 } | |
| 1990 return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 1991 } | |
| 1992 | |
| 1993 void operator[]=(int index, int value) { | |
| 1994 if (index < 0 || index >= _length) { | |
| 1995 throw new IndexOutOfRangeException(index); | |
| 1996 } | |
| 1997 _array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value)); | |
| 1998 } | |
| 1999 | |
| 2000 Iterator<int> iterator() { | |
| 2001 return new _ByteArrayIterator<int>(this); | |
| 2002 } | |
| 2003 | |
| 2004 List<int> getRange(int start, int length) { | |
| 2005 _rangeCheck(this, start, length); | |
| 2006 Uint32Array result = new Uint32Array(length); | |
| 2007 result.setRange(0, length, this, start); | |
| 2008 return result; | |
| 2009 } | |
| 2010 | |
| 2011 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2012 Arrays.copy(from, startFrom, this, start, length); | |
| 2013 } | |
| 2014 | |
| 2015 String toString() { | |
| 2016 return Collections.collectionToString(this); | |
| 2017 } | |
| 2018 | |
| 2019 int bytesPerElement() { | |
| 2020 return _BYTES_PER_ELEMENT; | |
| 2021 } | |
| 2022 | |
| 2023 int lengthInBytes() { | |
| 2024 return _length * _BYTES_PER_ELEMENT; | |
| 2025 } | |
| 2026 | |
| 2027 ByteArray asByteArray([int start = 0, int length]) { | |
| 2028 if (length == null) { | |
| 2029 length = this.lengthInBytes(); | |
| 2030 } | |
| 2031 _rangeCheck(start, length); | |
| 2032 return _array.subByteArray(_offset + start, length); | |
| 2033 } | |
| 2034 | |
| 2035 static final int _BYTES_PER_ELEMENT = 4; | |
| 2036 final ByteArray _array; | |
| 2037 final int _offset; | |
| 2038 final int _length; | |
| 2039 } | |
| 2040 | |
| 2041 | |
| 2042 class _Int64ArrayView extends _ByteArrayViewBase implements Int64Array { | |
| 2043 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2044 : _array = array, | |
| 2045 _offset = offsetInBytes, | |
| 2046 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 2047 : length { | |
| 2048 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2049 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2050 } | |
| 2051 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 2052 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2053 throw new IndexOutOfRangeException(length); | |
| 2054 } | |
| 2055 } | |
| 2056 | |
| 2057 get length() { | |
| 2058 return _length; | |
| 2059 } | |
| 2060 | |
| 2061 int operator[](int index) { | |
| 2062 if (index < 0 || index >= _length) { | |
| 2063 throw new IndexOutOfRangeException(index); | |
| 2064 } | |
| 2065 return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2066 } | |
| 2067 | |
| 2068 void operator[]=(int index, int value) { | |
| 2069 if (index < 0 || index >= _length) { | |
| 2070 throw new IndexOutOfRangeException(index); | |
| 2071 } | |
| 2072 _array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value)); | |
| 2073 } | |
| 2074 | |
| 2075 Iterator<int> iterator() { | |
| 2076 return new _ByteArrayIterator<int>(this); | |
| 2077 } | |
| 2078 | |
| 2079 List<int> getRange(int start, int length) { | |
| 2080 _rangeCheck(this, start, length); | |
| 2081 Int64Array result = new Int64Array(length); | |
| 2082 result.setRange(0, length, this, start); | |
| 2083 return result; | |
| 2084 } | |
| 2085 | |
| 2086 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2087 Arrays.copy(from, startFrom, this, start, length); | |
| 2088 } | |
| 2089 | |
| 2090 String toString() { | |
| 2091 return Collections.collectionToString(this); | |
| 2092 } | |
| 2093 | |
| 2094 int bytesPerElement() { | |
| 2095 return _BYTES_PER_ELEMENT; | |
| 2096 } | |
| 2097 | |
| 2098 int lengthInBytes() { | |
| 2099 return _length * _BYTES_PER_ELEMENT; | |
| 2100 } | |
| 2101 | |
| 2102 ByteArray asByteArray([int start = 0, int length]) { | |
| 2103 if (length == null) { | |
| 2104 length = this.lengthInBytes(); | |
| 2105 } | |
| 2106 _rangeCheck(start, length); | |
| 2107 return _array.subByteArray(_offset + start, length); | |
| 2108 } | |
| 2109 | |
| 2110 static final int _BYTES_PER_ELEMENT = 8; | |
| 2111 final ByteArray _array; | |
| 2112 final int _offset; | |
| 2113 final int _length; | |
| 2114 } | |
| 2115 | |
| 2116 | |
| 2117 class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64Array { | |
| 2118 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2119 : _array = array, | |
| 2120 _offset = offsetInBytes, | |
| 2121 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 2122 : length { | |
| 2123 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2124 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2125 } | |
| 2126 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 2127 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2128 throw new IndexOutOfRangeException(length); | |
| 2129 } | |
| 2130 } | |
| 2131 | |
| 2132 get length() { | |
| 2133 return _length; | |
| 2134 } | |
| 2135 | |
| 2136 int operator[](int index) { | |
| 2137 if (index < 0 || index >= _length) { | |
| 2138 throw new IndexOutOfRangeException(index); | |
| 2139 } | |
| 2140 return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2141 } | |
| 2142 | |
| 2143 void operator[]=(int index, int value) { | |
| 2144 if (index < 0 || index >= _length) { | |
| 2145 throw new IndexOutOfRangeException(index); | |
| 2146 } | |
| 2147 _array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value)); | |
| 2148 } | |
| 2149 | |
| 2150 Iterator<int> iterator() { | |
| 2151 return new _ByteArrayIterator<int>(this); | |
| 2152 } | |
| 2153 | |
| 2154 List<int> getRange(int start, int length) { | |
| 2155 _rangeCheck(this, start, length); | |
| 2156 Uint64Array result = new Uint64Array(length); | |
| 2157 result.setRange(0, length, this, start); | |
| 2158 return result; | |
| 2159 } | |
| 2160 | |
| 2161 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2162 Arrays.copy(from, startFrom, this, start, length); | |
| 2163 } | |
| 2164 | |
| 2165 String toString() { | |
| 2166 return Collections.collectionToString(this); | |
| 2167 } | |
| 2168 | |
| 2169 int bytesPerElement() { | |
| 2170 return _BYTES_PER_ELEMENT; | |
| 2171 } | |
| 2172 | |
| 2173 int lengthInBytes() { | |
| 2174 return _length * _BYTES_PER_ELEMENT; | |
| 2175 } | |
| 2176 | |
| 2177 ByteArray asByteArray([int start = 0, int length]) { | |
| 2178 if (length == null) { | |
| 2179 length = this.lengthInBytes(); | |
| 2180 } | |
| 2181 _rangeCheck(start, length); | |
| 2182 return _array.subByteArray(_offset + start, length); | |
| 2183 } | |
| 2184 | |
| 2185 static final int _BYTES_PER_ELEMENT = 8; | |
| 2186 final ByteArray _array; | |
| 2187 final int _offset; | |
| 2188 final int _length; | |
| 2189 } | |
| 2190 | |
| 2191 | |
| 2192 class _Float32ArrayView extends _ByteArrayViewBase implements Float32Array { | |
| 2193 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2194 : _array = array, | |
| 2195 _offset = offsetInBytes, | |
| 2196 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 2197 : length { | |
| 2198 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2199 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2200 } | |
| 2201 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 2202 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2203 throw new IndexOutOfRangeException(length); | |
| 2204 } | |
| 2205 } | |
| 2206 | |
| 2207 get length() { | |
| 2208 return _length; | |
| 2209 } | |
| 2210 | |
| 2211 double operator[](int index) { | |
| 2212 if (index < 0 || index >= _length) { | |
| 2213 throw new IndexOutOfRangeException(index); | |
| 2214 } | |
| 2215 return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2216 } | |
| 2217 | |
| 2218 void operator[]=(int index, double value) { | |
| 2219 if (index < 0 || index >= _length) { | |
| 2220 throw new IndexOutOfRangeException(index); | |
| 2221 } | |
| 2222 _array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value); | |
| 2223 } | |
| 2224 | |
| 2225 Iterator<double> iterator() { | |
| 2226 return new _ByteArrayIterator<double>(this); | |
| 2227 } | |
| 2228 | |
| 2229 List<double> getRange(int start, int length) { | |
| 2230 _rangeCheck(this, start, length); | |
| 2231 Float32Array result = new Float32Array(length); | |
| 2232 result.setRange(0, length, this, start); | |
| 2233 return result; | |
| 2234 } | |
| 2235 | |
| 2236 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 2237 Arrays.copy(from, startFrom, this, start, length); | |
| 2238 } | |
| 2239 | |
| 2240 String toString() { | |
| 2241 return Collections.collectionToString(this); | |
| 2242 } | |
| 2243 | |
| 2244 int bytesPerElement() { | |
| 2245 return _BYTES_PER_ELEMENT; | |
| 2246 } | |
| 2247 | |
| 2248 int lengthInBytes() { | |
| 2249 return _length * _BYTES_PER_ELEMENT; | |
| 2250 } | |
| 2251 | |
| 2252 ByteArray asByteArray([int start = 0, int length]) { | |
| 2253 if (length == null) { | |
| 2254 length = this.lengthInBytes(); | |
| 2255 } | |
| 2256 _rangeCheck(start, length); | |
| 2257 return _array.subByteArray(_offset + start, length); | |
| 2258 } | |
| 2259 | |
| 2260 static final int _BYTES_PER_ELEMENT = 4; | |
| 2261 final ByteArray _array; | |
| 2262 final int _offset; | |
| 2263 final int _length; | |
| 2264 } | |
| 2265 | |
| 2266 | |
| 2267 class _Float64ArrayView extends _ByteArrayViewBase implements Float64Array { | |
| 2268 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2269 : _array = array, | |
| 2270 _offset = offsetInBytes, | |
| 2271 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) | |
| 2272 : length { | |
| 2273 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2274 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2275 } | |
| 2276 int lengthInBytes = length * _BYTES_PER_ELEMENT; | |
| 2277 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2278 throw new IndexOutOfRangeException(length); | |
| 2279 } | |
| 2280 } | |
| 2281 | |
| 2282 get length() { | |
| 2283 return _length; | |
| 2284 } | |
| 2285 | |
| 2286 double operator[](int index) { | |
| 2287 if (index < 0 || index >= _length) { | |
| 2288 throw new IndexOutOfRangeException(index); | |
| 2289 } | |
| 2290 return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2291 } | |
| 2292 | |
| 2293 void operator[]=(int index, double value) { | |
| 2294 if (index < 0 || index >= _length) { | |
| 2295 throw new IndexOutOfRangeException(index); | |
| 2296 } | |
| 2297 _array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value); | |
| 2298 } | |
| 2299 | |
| 2300 Iterator<double> iterator() { | |
| 2301 return new _ByteArrayIterator<double>(this); | |
| 2302 } | |
| 2303 | |
| 2304 List<double> getRange(int start, int length) { | |
| 2305 _rangeCheck(this, start, length); | |
| 2306 Float64Array result = new Float64Array(length); | |
| 2307 result.setRange(0, length, this, start); | |
| 2308 return result; | |
| 2309 } | |
| 2310 | |
| 2311 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 2312 Arrays.copy(from, startFrom, this, start, length); | |
| 2313 } | |
| 2314 | |
| 2315 String toString() { | |
| 2316 return Collections.collectionToString(this); | |
| 2317 } | |
| 2318 | |
| 2319 int bytesPerElement() { | |
| 2320 return _BYTES_PER_ELEMENT; | |
| 2321 } | |
| 2322 | |
| 2323 int lengthInBytes() { | |
| 2324 return _length * _BYTES_PER_ELEMENT; | |
| 2325 } | |
| 2326 | |
| 2327 ByteArray asByteArray([int start = 0, int length]) { | |
| 2328 if (length == null) { | |
| 2329 length = this.lengthInBytes(); | |
| 2330 } | |
| 2331 _rangeCheck(start, length); | |
| 2332 return _array.subByteArray(_offset + start, length); | |
| 2333 } | |
| 2334 | |
| 2335 static final int _BYTES_PER_ELEMENT = 8; | |
| 2336 final ByteArray _array; | |
| 2337 final int _offset; | |
| 2338 final int _length; | |
| 2339 } | |
| OLD | NEW |