| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 patch class Int8List { | |
| 6 /* patch */ factory Int8List(int length) { | |
| 7 return new _Int8Array(length); | |
| 8 } | |
| 9 | |
| 10 /* patch */ factory Int8List.transferable(int length) { | |
| 11 return _newTransferable(length); | |
| 12 } | |
| 13 | |
| 14 /* patch */ factory Int8List.view(ByteArray array, | |
| 15 [int start = 0, int length]) { | |
| 16 return new _Int8ArrayView(array, start, length); | |
| 17 } | |
| 18 | |
| 19 static _ExternalInt8Array _newTransferable(int length) | |
| 20 native "Int8List_newTransferable"; | |
| 21 } | |
| 22 | |
| 23 | |
| 24 patch class Uint8List { | |
| 25 /* patch */ factory Uint8List(int length) { | |
| 26 return new _Uint8Array(length); | |
| 27 } | |
| 28 | |
| 29 /* patch */ factory Uint8List.transferable(int length) { | |
| 30 return _newTransferable(length); | |
| 31 } | |
| 32 | |
| 33 /* patch */ factory Uint8List.view(ByteArray array, | |
| 34 [int start = 0, int length]) { | |
| 35 return new _Uint8ArrayView(array, start, length); | |
| 36 } | |
| 37 | |
| 38 static _ExternalUint8Array _newTransferable(int length) | |
| 39 native "Uint8List_newTransferable"; | |
| 40 } | |
| 41 | |
| 42 | |
| 43 patch class Uint8ClampedList { | |
| 44 /* patch */ factory Uint8ClampedList(int length) { | |
| 45 return new _Uint8ClampedArray(length); | |
| 46 } | |
| 47 | |
| 48 /* patch */ factory Uint8ClampedList.transferable(int length) { | |
| 49 return _newTransferable(length); | |
| 50 } | |
| 51 | |
| 52 /* patch */ factory Uint8ClampedList.view(ByteArray array, | |
| 53 [int start = 0, int length]) { | |
| 54 return new _Uint8ClampedArrayView(array, start, length); | |
| 55 } | |
| 56 | |
| 57 static _ExternalUint8ClampedArray _newTransferable(int length) | |
| 58 native "Uint8ClampedList_newTransferable"; | |
| 59 } | |
| 60 | |
| 61 | |
| 62 patch class Int16List { | |
| 63 /* patch */ factory Int16List(int length) { | |
| 64 return new _Int16Array(length); | |
| 65 } | |
| 66 | |
| 67 /* patch */ factory Int16List.transferable(int length) { | |
| 68 return _newTransferable(length); | |
| 69 } | |
| 70 | |
| 71 /* patch */ factory Int16List.view(ByteArray array, | |
| 72 [int start = 0, int length]) { | |
| 73 return new _Int16ArrayView(array, start, length); | |
| 74 } | |
| 75 | |
| 76 static _ExternalInt16Array _newTransferable(int length) | |
| 77 native "Int16List_newTransferable"; | |
| 78 } | |
| 79 | |
| 80 | |
| 81 patch class Uint16List { | |
| 82 /* patch */ factory Uint16List(int length) { | |
| 83 return new _Uint16Array(length); | |
| 84 } | |
| 85 | |
| 86 /* patch */ factory Uint16List.transferable(int length) { | |
| 87 return _newTransferable(length); | |
| 88 } | |
| 89 | |
| 90 /* patch */ factory Uint16List.view(ByteArray array, | |
| 91 [int start = 0, int length]) { | |
| 92 return new _Uint16ArrayView(array, start, length); | |
| 93 } | |
| 94 | |
| 95 static _ExternalUint16Array _newTransferable(int length) | |
| 96 native "Uint16List_newTransferable"; | |
| 97 } | |
| 98 | |
| 99 | |
| 100 patch class Int32List { | |
| 101 /* patch */ factory Int32List(int length) { | |
| 102 return new _Int32Array(length); | |
| 103 } | |
| 104 | |
| 105 /* patch */ factory Int32List.transferable(int length) { | |
| 106 return _newTransferable(length); | |
| 107 } | |
| 108 | |
| 109 /* patch */ factory Int32List.view(ByteArray array, | |
| 110 [int start = 0, int length]) { | |
| 111 return new _Int32ArrayView(array, start, length); | |
| 112 } | |
| 113 | |
| 114 static _ExternalInt32Array _newTransferable(int length) | |
| 115 native "Int32List_newTransferable"; | |
| 116 } | |
| 117 | |
| 118 | |
| 119 patch class Uint32List { | |
| 120 /* patch */ factory Uint32List(int length) { | |
| 121 return new _Uint32Array(length); | |
| 122 } | |
| 123 | |
| 124 /* patch */ factory Uint32List.transferable(int length) { | |
| 125 return _newTransferable(length); | |
| 126 } | |
| 127 | |
| 128 /* patch */ factory Uint32List.view(ByteArray array, | |
| 129 [int start = 0, int length]) { | |
| 130 return new _Uint32ArrayView(array, start, length); | |
| 131 } | |
| 132 | |
| 133 static _ExternalUint32Array _newTransferable(int length) | |
| 134 native "Uint32List_newTransferable"; | |
| 135 } | |
| 136 | |
| 137 | |
| 138 patch class Int64List { | |
| 139 /* patch */ factory Int64List(int length) { | |
| 140 return new _Int64Array(length); | |
| 141 } | |
| 142 | |
| 143 /* patch */ factory Int64List.transferable(int length) { | |
| 144 return _newTransferable(length); | |
| 145 } | |
| 146 | |
| 147 /* patch */ factory Int64List.view(ByteArray array, | |
| 148 [int start = 0, int length]) { | |
| 149 return new _Int64ArrayView(array, start, length); | |
| 150 } | |
| 151 | |
| 152 static _ExternalInt64Array _newTransferable(int length) | |
| 153 native "Int64List_newTransferable"; | |
| 154 } | |
| 155 | |
| 156 | |
| 157 patch class Uint64List { | |
| 158 /* patch */ factory Uint64List(int length) { | |
| 159 return new _Uint64Array(length); | |
| 160 } | |
| 161 | |
| 162 /* patch */ factory Uint64List.transferable(int length) { | |
| 163 return _newTransferable(length); | |
| 164 } | |
| 165 | |
| 166 /* patch */ factory Uint64List.view(ByteArray array, | |
| 167 [int start = 0, int length]) { | |
| 168 return new _Uint64ArrayView(array, start, length); | |
| 169 } | |
| 170 | |
| 171 static _ExternalUint64Array _newTransferable(int length) | |
| 172 native "Uint64List_newTransferable"; | |
| 173 } | |
| 174 | |
| 175 | |
| 176 patch class Float32List { | |
| 177 /* patch */ factory Float32List(int length) { | |
| 178 return new _Float32Array(length); | |
| 179 } | |
| 180 | |
| 181 /* patch */ factory Float32List.transferable(int length) { | |
| 182 return _newTransferable(length); | |
| 183 } | |
| 184 | |
| 185 /* patch */ factory Float32List.view(ByteArray array, | |
| 186 [int start = 0, int length]) { | |
| 187 return new _Float32ArrayView(array, start, length); | |
| 188 } | |
| 189 | |
| 190 static _ExternalFloat32Array _newTransferable(int length) | |
| 191 native "Float32List_newTransferable"; | |
| 192 } | |
| 193 | |
| 194 | |
| 195 patch class Float64List { | |
| 196 /* patch */ factory Float64List(int length) { | |
| 197 return new _Float64Array(length); | |
| 198 } | |
| 199 | |
| 200 /* patch */ factory Float64List.transferable(int length) { | |
| 201 return _newTransferable(length); | |
| 202 } | |
| 203 | |
| 204 /* patch */ factory Float64List.view(ByteArray array, | |
| 205 [int start = 0, int length]) { | |
| 206 return new _Float64ArrayView(array, start, length); | |
| 207 } | |
| 208 | |
| 209 static _ExternalFloat64Array _newTransferable(int length) | |
| 210 native "Float64List_newTransferable"; | |
| 211 } | |
| 212 | |
| 213 | |
| 214 abstract class _ByteArrayBase { | |
| 215 int lengthInBytes(); | |
| 216 | |
| 217 int bytesPerElement(); | |
| 218 | |
| 219 operator[](int index); | |
| 220 | |
| 221 // Methods implementing the Collection interface. | |
| 222 | |
| 223 bool contains(element) => IterableMixinWorkaround.contains(this, element); | |
| 224 | |
| 225 void forEach(void f(element)) { | |
| 226 var len = this.length; | |
| 227 for (var i = 0; i < len; i++) { | |
| 228 f(this[i]); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 Iterable map(f(int element)) { | |
| 233 return IterableMixinWorkaround.mapList(this, f); | |
| 234 } | |
| 235 | |
| 236 String join([String separator]) { | |
| 237 return IterableMixinWorkaround.join(this, separator); | |
| 238 } | |
| 239 | |
| 240 dynamic reduce(dynamic initialValue, | |
| 241 dynamic combine(dynamic initialValue, element)) { | |
| 242 return IterableMixinWorkaround.reduce(this, initialValue, combine); | |
| 243 } | |
| 244 | |
| 245 Collection where(bool f(int element)) { | |
| 246 return IterableMixinWorkaround.where(this, f); | |
| 247 } | |
| 248 | |
| 249 Iterable expand(Iterable f(int element)) { | |
| 250 return IterableMixinWorkaround.expand(this, f); | |
| 251 } | |
| 252 | |
| 253 Iterable<int> take(int n) { | |
| 254 return IterableMixinWorkaround.takeList(this, n); | |
| 255 } | |
| 256 | |
| 257 Iterable<int> takeWhile(bool test(int value)) { | |
| 258 return IterableMixinWorkaround.takeWhile(this, test); | |
| 259 } | |
| 260 | |
| 261 Iterable<int> skip(int n) { | |
| 262 return IterableMixinWorkaround.skipList(this, n); | |
| 263 } | |
| 264 | |
| 265 Iterable<int> skipWhile(bool test(int value)) { | |
| 266 return IterableMixinWorkaround.skipWhile(this, test); | |
| 267 } | |
| 268 | |
| 269 bool every(bool f(element)) { | |
| 270 return IterableMixinWorkaround.every(this, f); | |
| 271 } | |
| 272 | |
| 273 bool any(bool f(element)) { | |
| 274 return IterableMixinWorkaround.any(this, f); | |
| 275 } | |
| 276 | |
| 277 int firstWhere(bool test(int value), {int orElse()}) { | |
| 278 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
| 279 } | |
| 280 | |
| 281 int lastWhere(bool test(int value), {int orElse()}) { | |
| 282 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
| 283 } | |
| 284 | |
| 285 int singleWhere(bool test(int value)) { | |
| 286 return IterableMixinWorkaround.singleWhere(this, test); | |
| 287 } | |
| 288 | |
| 289 int elementAt(int index) { | |
| 290 return this[index]; | |
| 291 } | |
| 292 | |
| 293 bool get isEmpty { | |
| 294 return this.length == 0; | |
| 295 } | |
| 296 | |
| 297 int get length { | |
| 298 return _length(); | |
| 299 } | |
| 300 | |
| 301 // Methods implementing the List interface. | |
| 302 | |
| 303 set length(newLength) { | |
| 304 throw new UnsupportedError( | |
| 305 "Cannot resize a non-extendable array"); | |
| 306 } | |
| 307 | |
| 308 void add(value) { | |
| 309 throw new UnsupportedError( | |
| 310 "Cannot add to a non-extendable array"); | |
| 311 } | |
| 312 | |
| 313 void addLast(value) { | |
| 314 throw new UnsupportedError( | |
| 315 "Cannot add to a non-extendable array"); | |
| 316 } | |
| 317 | |
| 318 void addAll(Iterable value) { | |
| 319 throw new UnsupportedError( | |
| 320 "Cannot add to a non-extendable array"); | |
| 321 } | |
| 322 | |
| 323 void sort([int compare(var a, var b)]) { | |
| 324 return IterableMixinWorkaround.sortList(this, compare); | |
| 325 } | |
| 326 | |
| 327 int indexOf(element, [int start = 0]) { | |
| 328 return IterableMixinWorkaround.indexOfList(this, element, start); | |
| 329 } | |
| 330 | |
| 331 int lastIndexOf(element, [int start = null]) { | |
| 332 return IterableMixinWorkaround.lastIndexOfList(this, element, start); | |
| 333 } | |
| 334 | |
| 335 void clear() { | |
| 336 throw new UnsupportedError( | |
| 337 "Cannot remove from a non-extendable array"); | |
| 338 } | |
| 339 | |
| 340 int removeLast() { | |
| 341 throw new UnsupportedError( | |
| 342 "Cannot remove from a non-extendable array"); | |
| 343 } | |
| 344 | |
| 345 void remove(Object element) { | |
| 346 throw new UnsupportedError( | |
| 347 "Cannot remove from a non-extendable array"); | |
| 348 } | |
| 349 | |
| 350 void removeAll(Iterable elements) { | |
| 351 throw new UnsupportedError( | |
| 352 "Cannot remove from a non-extendable array"); | |
| 353 } | |
| 354 | |
| 355 void retainAll(Iterable elements) { | |
| 356 throw new UnsupportedError( | |
| 357 "Cannot remove from a non-extendable array"); | |
| 358 } | |
| 359 | |
| 360 void removeWhere(bool test(int element)) { | |
| 361 throw new UnsupportedError( | |
| 362 "Cannot remove from a non-extendable array"); | |
| 363 } | |
| 364 | |
| 365 void retainWhere(bool test(int element)) { | |
| 366 throw new UnsupportedError( | |
| 367 "Cannot remove from a non-extendable array"); | |
| 368 } | |
| 369 | |
| 370 int get first { | |
| 371 if (length > 0) return this[0]; | |
| 372 throw new StateError("No elements"); | |
| 373 } | |
| 374 | |
| 375 int get last { | |
| 376 if (length > 0) return this[length - 1]; | |
| 377 throw new StateError("No elements"); | |
| 378 } | |
| 379 | |
| 380 int get single { | |
| 381 if (length == 1) return this[0]; | |
| 382 if (length == 0) throw new StateError("No elements"); | |
| 383 throw new StateError("More than one element"); | |
| 384 } | |
| 385 | |
| 386 int min([int compare(int a, int b)]) => IterableMixinWorkaround.min(this, comp
are); | |
| 387 | |
| 388 int max([int compare(int a, int b)]) => IterableMixinWorkaround.max(this, comp
are); | |
| 389 | |
| 390 void removeRange(int start, int length) { | |
| 391 throw new UnsupportedError( | |
| 392 "Cannot remove from a non-extendable array"); | |
| 393 } | |
| 394 | |
| 395 void insertRange(int start, int length, [initialValue]) { | |
| 396 throw new UnsupportedError( | |
| 397 "Cannot add to a non-extendable array"); | |
| 398 } | |
| 399 | |
| 400 ByteArray asByteArray([int start = 0, int length]) { | |
| 401 if (length == null) { | |
| 402 length = this.length; | |
| 403 } | |
| 404 _rangeCheck(this.length, start, length); | |
| 405 return new _ByteArrayView(this, | |
| 406 start * this.bytesPerElement(), | |
| 407 length * this.bytesPerElement()); | |
| 408 } | |
| 409 | |
| 410 List<int> toList({ bool growable: true }) { | |
| 411 return new List<int>.from(this, growable: growable); | |
| 412 } | |
| 413 | |
| 414 Set<int> toSet() { | |
| 415 return new Set<int>.from(this); | |
| 416 } | |
| 417 | |
| 418 int _length() native "ByteArray_getLength"; | |
| 419 | |
| 420 void _setRange(int startInBytes, int lengthInBytes, | |
| 421 _ByteArrayBase from, int startFromInBytes) | |
| 422 native "ByteArray_setRange"; | |
| 423 | |
| 424 int _getInt8(int byteOffset) native "ByteArray_getInt8"; | |
| 425 int _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; | |
| 426 | |
| 427 int _getUint8(int byteOffset) native "ByteArray_getUint8"; | |
| 428 int _setUint8(int byteOffset, int value) native "ByteArray_setUint8"; | |
| 429 | |
| 430 int _getInt16(int byteOffset) native "ByteArray_getInt16"; | |
| 431 int _setInt16(int byteOffset, int value) native "ByteArray_setInt16"; | |
| 432 | |
| 433 int _getUint16(int byteOffset) native "ByteArray_getUint16"; | |
| 434 int _setUint16(int byteOffset, int value) native "ByteArray_setUint16"; | |
| 435 | |
| 436 int _getInt32(int byteOffset) native "ByteArray_getInt32"; | |
| 437 int _setInt32(int byteOffset, int value) native "ByteArray_setInt32"; | |
| 438 | |
| 439 int _getUint32(int byteOffset) native "ByteArray_getUint32"; | |
| 440 int _setUint32(int byteOffset, int value) native "ByteArray_setUint32"; | |
| 441 | |
| 442 int _getInt64(int byteOffset) native "ByteArray_getInt64"; | |
| 443 int _setInt64(int byteOffset, int value) native "ByteArray_setInt64"; | |
| 444 | |
| 445 int _getUint64(int byteOffset) native "ByteArray_getUint64"; | |
| 446 int _setUint64(int byteOffset, int value) native "ByteArray_setUint64"; | |
| 447 | |
| 448 double _getFloat32(int byteOffset) native "ByteArray_getFloat32"; | |
| 449 int _setFloat32(int byteOffset, double value) native "ByteArray_setFloat32"; | |
| 450 | |
| 451 double _getFloat64(int byteOffset) native "ByteArray_getFloat64"; | |
| 452 int _setFloat64(int byteOffset, double value) native "ByteArray_setFloat64"; | |
| 453 } | |
| 454 | |
| 455 | |
| 456 int _toInt(int value, int mask) { | |
| 457 value &= mask; | |
| 458 if (value > (mask >> 1)) value -= mask + 1; | |
| 459 return value; | |
| 460 } | |
| 461 | |
| 462 int _toInt8(int value) { | |
| 463 return _toInt(value, 0xFF); | |
| 464 } | |
| 465 int _toUint8(int value) { | |
| 466 return value & 0xFF; | |
| 467 } | |
| 468 int _toClampedUint8(int value) { | |
| 469 if (value < 0) return 0; | |
| 470 if (value > 0xFF) return 0xFF; | |
| 471 return value; | |
| 472 } | |
| 473 | |
| 474 | |
| 475 int _toInt16(int value) { | |
| 476 return _toInt(value, 0xFFFF); | |
| 477 } | |
| 478 int _toUint16(int value) { | |
| 479 return value & 0xFFFF; | |
| 480 } | |
| 481 | |
| 482 | |
| 483 int _toInt32(int value) { | |
| 484 return _toInt(value, 0xFFFFFFFF); | |
| 485 } | |
| 486 int _toUint32(int value) { | |
| 487 return value & 0xFFFFFFFF; | |
| 488 } | |
| 489 | |
| 490 | |
| 491 int _toInt64(int value) { | |
| 492 return _toInt(value, 0xFFFFFFFFFFFFFFFF); | |
| 493 } | |
| 494 int _toUint64(int value) { | |
| 495 return value & 0xFFFFFFFFFFFFFFFF; | |
| 496 } | |
| 497 | |
| 498 | |
| 499 void _rangeCheck(int listLength, int start, int length) { | |
| 500 if (length < 0) { | |
| 501 throw new RangeError.value(length); | |
| 502 } | |
| 503 if (start < 0) { | |
| 504 throw new RangeError.value(start); | |
| 505 } | |
| 506 if (start + length > listLength) { | |
| 507 throw new RangeError.value(start + length); | |
| 508 } | |
| 509 } | |
| 510 | |
| 511 | |
| 512 int _requireInteger(object) { | |
| 513 if (object is int) { | |
| 514 return object; | |
| 515 } | |
| 516 throw new ArgumentError("$object is not an integer"); | |
| 517 } | |
| 518 | |
| 519 | |
| 520 int _requireIntegerOrNull(object, value) { | |
| 521 if (object is int) { | |
| 522 return object; | |
| 523 } | |
| 524 if (object == null) { | |
| 525 return _requireInteger(value); | |
| 526 } | |
| 527 throw new ArgumentError("$object is not an integer or null"); | |
| 528 } | |
| 529 | |
| 530 | |
| 531 class _Int8Array extends _ByteArrayBase implements Int8List { | |
| 532 factory _Int8Array(int length) { | |
| 533 return _new(length); | |
| 534 } | |
| 535 | |
| 536 factory _Int8Array.view(ByteArray array, [int start = 0, int length]) { | |
| 537 if (length == null) { | |
| 538 length = array.lengthInBytes(); | |
| 539 } | |
| 540 return new _Int8ArrayView(array, start, length); | |
| 541 } | |
| 542 | |
| 543 int operator[](int index) { | |
| 544 return _getIndexed(index); | |
| 545 } | |
| 546 | |
| 547 int operator[]=(int index, int value) { | |
| 548 _setIndexed(index, _toInt8(value)); | |
| 549 } | |
| 550 | |
| 551 Iterator<int> get iterator { | |
| 552 return new _ByteArrayIterator<int>(this); | |
| 553 } | |
| 554 | |
| 555 List<int> sublist(int start, [int end]) { | |
| 556 if (end == null) end = this.length; | |
| 557 int length = end - start; | |
| 558 _rangeCheck(this.length, start, length); | |
| 559 List<int> result = _new(length); | |
| 560 result.setRange(0, length, this, start); | |
| 561 return result; | |
| 562 } | |
| 563 | |
| 564 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 565 | |
| 566 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 567 if (from is _Int8Array) { | |
| 568 _setRange(start * _BYTES_PER_ELEMENT, | |
| 569 length * _BYTES_PER_ELEMENT, | |
| 570 from, | |
| 571 startFrom * _BYTES_PER_ELEMENT); | |
| 572 } else { | |
| 573 IterableMixinWorkaround.setRangeList( | |
| 574 this, start, length, from, startFrom); | |
| 575 } | |
| 576 } | |
| 577 | |
| 578 String toString() { | |
| 579 return Collections.collectionToString(this); | |
| 580 } | |
| 581 | |
| 582 int bytesPerElement() { | |
| 583 return _BYTES_PER_ELEMENT; | |
| 584 } | |
| 585 | |
| 586 int lengthInBytes() { | |
| 587 return _length() * _BYTES_PER_ELEMENT; | |
| 588 } | |
| 589 | |
| 590 static const int _BYTES_PER_ELEMENT = 1; | |
| 591 | |
| 592 static _Int8Array _new(int length) native "Int8Array_new"; | |
| 593 | |
| 594 int _getIndexed(int index) native "Int8Array_getIndexed"; | |
| 595 int _setIndexed(int index, int value) native "Int8Array_setIndexed"; | |
| 596 } | |
| 597 | |
| 598 | |
| 599 class _Uint8Array extends _ByteArrayBase implements Uint8List { | |
| 600 factory _Uint8Array(int length) { | |
| 601 return _new(length); | |
| 602 } | |
| 603 | |
| 604 factory _Uint8Array.view(ByteArray array, [int start = 0, int length]) { | |
| 605 if (length == null) { | |
| 606 length = array.lengthInBytes(); | |
| 607 } | |
| 608 return new _Uint8ArrayView(array, start, length); | |
| 609 } | |
| 610 | |
| 611 int operator[](int index) { | |
| 612 return _getIndexed(index); | |
| 613 } | |
| 614 | |
| 615 int operator[]=(int index, int value) { | |
| 616 _setIndexed(index, _toUint8(value)); | |
| 617 } | |
| 618 | |
| 619 Iterator<int> get iterator { | |
| 620 return new _ByteArrayIterator<int>(this); | |
| 621 } | |
| 622 | |
| 623 List<int> sublist(int start, [int end]) { | |
| 624 if (end == null) end = this.length; | |
| 625 int length = end - start; | |
| 626 _rangeCheck(this.length, start, length); | |
| 627 List<int> result = _new(length); | |
| 628 result.setRange(0, length, this, start); | |
| 629 return result; | |
| 630 } | |
| 631 | |
| 632 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 633 | |
| 634 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 635 if (from is _Uint8Array || from is _ExternalUint8Array || | |
| 636 from is _Uint8ClampedArray || from is _ExternalUint8ClampedArray) { | |
| 637 _setRange(start * _BYTES_PER_ELEMENT, | |
| 638 length * _BYTES_PER_ELEMENT, | |
| 639 from, | |
| 640 startFrom * _BYTES_PER_ELEMENT); | |
| 641 } else { | |
| 642 IterableMixinWorkaround.setRangeList( | |
| 643 this, start, length, from, startFrom); | |
| 644 } | |
| 645 } | |
| 646 | |
| 647 String toString() { | |
| 648 return Collections.collectionToString(this); | |
| 649 } | |
| 650 | |
| 651 int bytesPerElement() { | |
| 652 return _BYTES_PER_ELEMENT; | |
| 653 } | |
| 654 | |
| 655 int lengthInBytes() { | |
| 656 return _length() * _BYTES_PER_ELEMENT; | |
| 657 } | |
| 658 | |
| 659 static const int _BYTES_PER_ELEMENT = 1; | |
| 660 | |
| 661 static _Uint8Array _new(int length) native "Uint8Array_new"; | |
| 662 | |
| 663 int _getIndexed(int index) native "Uint8Array_getIndexed"; | |
| 664 int _setIndexed(int index, int value) native "Uint8Array_setIndexed"; | |
| 665 } | |
| 666 | |
| 667 | |
| 668 class _Uint8ClampedArray extends _ByteArrayBase implements Uint8ClampedList { | |
| 669 factory _Uint8ClampedArray(int length) { | |
| 670 return _new(length); | |
| 671 } | |
| 672 | |
| 673 factory _Uint8ClampedArray.view(ByteArray array, | |
| 674 [int start = 0, int length]) { | |
| 675 if (length == null) { | |
| 676 length = array.lengthInBytes(); | |
| 677 } | |
| 678 return new _Uint8ClampedArrayView(array, start, length); | |
| 679 } | |
| 680 | |
| 681 int operator[](int index) { | |
| 682 return _getIndexed(index); | |
| 683 } | |
| 684 | |
| 685 int operator[]=(int index, int value) { | |
| 686 _setIndexed(index, _toClampedUint8(value)); | |
| 687 } | |
| 688 | |
| 689 Iterator<int> get iterator { | |
| 690 return new _ByteArrayIterator<int>(this); | |
| 691 } | |
| 692 | |
| 693 List<int> sublist(int start, [int end]) { | |
| 694 if (end == null) end = this.length; | |
| 695 int length = end - start; | |
| 696 _rangeCheck(this.length, start, length); | |
| 697 List<int> result = _new(length); | |
| 698 result.setRange(0, length, this, start); | |
| 699 return result; | |
| 700 } | |
| 701 | |
| 702 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 703 | |
| 704 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 705 if (from is _Uint8Array || from is _ExternalUint8Array || | |
| 706 from is _Uint8ClampedArray || from is _ExternalUint8ClampedArray) { | |
| 707 _setRange(start * _BYTES_PER_ELEMENT, | |
| 708 length * _BYTES_PER_ELEMENT, | |
| 709 from, | |
| 710 startFrom * _BYTES_PER_ELEMENT); | |
| 711 } else { | |
| 712 IterableMixinWorkaround.setRangeList( | |
| 713 this, start, length, from, startFrom); | |
| 714 } | |
| 715 } | |
| 716 | |
| 717 String toString() { | |
| 718 return Collections.collectionToString(this); | |
| 719 } | |
| 720 | |
| 721 int bytesPerElement() { | |
| 722 return _BYTES_PER_ELEMENT; | |
| 723 } | |
| 724 | |
| 725 int lengthInBytes() { | |
| 726 return _length() * _BYTES_PER_ELEMENT; | |
| 727 } | |
| 728 | |
| 729 static const int _BYTES_PER_ELEMENT = 1; | |
| 730 | |
| 731 static _Uint8ClampedArray _new(int length) native "Uint8ClampedArray_new"; | |
| 732 | |
| 733 int _getIndexed(int index) native "Uint8ClampedArray_getIndexed"; | |
| 734 int _setIndexed(int index, int value) native "Uint8ClampedArray_setIndexed"; | |
| 735 } | |
| 736 | |
| 737 | |
| 738 class _Int16Array extends _ByteArrayBase implements Int16List { | |
| 739 factory _Int16Array(int length) { | |
| 740 return _new(length); | |
| 741 } | |
| 742 | |
| 743 factory _Int16Array.view(ByteArray array, [int start = 0, int length]) { | |
| 744 if (length == null) { | |
| 745 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 746 } | |
| 747 return new _Int16ArrayView(array, start, length); | |
| 748 } | |
| 749 | |
| 750 int operator[](int index) { | |
| 751 return _getIndexed(index); | |
| 752 } | |
| 753 | |
| 754 int operator[]=(int index, int value) { | |
| 755 _setIndexed(index, _toInt16(value)); | |
| 756 } | |
| 757 | |
| 758 Iterator<int> get iterator { | |
| 759 return new _ByteArrayIterator<int>(this); | |
| 760 } | |
| 761 | |
| 762 List<int> sublist(int start, [int end]) { | |
| 763 if (end == null) end = this.length; | |
| 764 int length = end - start; | |
| 765 _rangeCheck(this.length, start, length); | |
| 766 List<int> result = _new(length); | |
| 767 result.setRange(0, length, this, start); | |
| 768 return result; | |
| 769 } | |
| 770 | |
| 771 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 772 | |
| 773 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 774 if (from is _Int16Array) { | |
| 775 _setRange(start * _BYTES_PER_ELEMENT, | |
| 776 length * _BYTES_PER_ELEMENT, | |
| 777 from, | |
| 778 startFrom * _BYTES_PER_ELEMENT); | |
| 779 } else { | |
| 780 IterableMixinWorkaround.setRangeList( | |
| 781 this, start, length, from, startFrom); | |
| 782 } | |
| 783 } | |
| 784 | |
| 785 String toString() { | |
| 786 return Collections.collectionToString(this); | |
| 787 } | |
| 788 | |
| 789 int bytesPerElement() { | |
| 790 return _BYTES_PER_ELEMENT; | |
| 791 } | |
| 792 | |
| 793 int lengthInBytes() { | |
| 794 return _length() * _BYTES_PER_ELEMENT; | |
| 795 } | |
| 796 | |
| 797 static const int _BYTES_PER_ELEMENT = 2; | |
| 798 | |
| 799 static _Int16Array _new(int length) native "Int16Array_new"; | |
| 800 | |
| 801 int _getIndexed(int index) native "Int16Array_getIndexed"; | |
| 802 int _setIndexed(int index, int value) native "Int16Array_setIndexed"; | |
| 803 } | |
| 804 | |
| 805 | |
| 806 class _Uint16Array extends _ByteArrayBase implements Uint16List { | |
| 807 factory _Uint16Array(int length) { | |
| 808 return _new(length); | |
| 809 } | |
| 810 | |
| 811 factory _Uint16Array.view(ByteArray array, [int start = 0, int length]) { | |
| 812 if (length == null) { | |
| 813 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 814 } | |
| 815 return new _Uint16ArrayView(array, start, length); | |
| 816 } | |
| 817 | |
| 818 int operator[](int index) { | |
| 819 return _getIndexed(index); | |
| 820 } | |
| 821 | |
| 822 int operator[]=(int index, int value) { | |
| 823 _setIndexed(index, _toUint16(value)); | |
| 824 } | |
| 825 | |
| 826 Iterator<int> get iterator { | |
| 827 return new _ByteArrayIterator<int>(this); | |
| 828 } | |
| 829 | |
| 830 List<int> sublist(int start, [int end]) { | |
| 831 if (end == null) end = this.length; | |
| 832 int length = end - start; | |
| 833 _rangeCheck(this.length, start, length); | |
| 834 List<int> result = _new(length); | |
| 835 result.setRange(0, length, this, start); | |
| 836 return result; | |
| 837 } | |
| 838 | |
| 839 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 840 | |
| 841 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 842 if (from is _Uint16Array) { | |
| 843 _setRange(start * _BYTES_PER_ELEMENT, | |
| 844 length * _BYTES_PER_ELEMENT, | |
| 845 from, | |
| 846 startFrom * _BYTES_PER_ELEMENT); | |
| 847 } else { | |
| 848 IterableMixinWorkaround.setRangeList( | |
| 849 this, start, length, from, startFrom); | |
| 850 } | |
| 851 } | |
| 852 | |
| 853 String toString() { | |
| 854 return Collections.collectionToString(this); | |
| 855 } | |
| 856 | |
| 857 int bytesPerElement() { | |
| 858 return _BYTES_PER_ELEMENT; | |
| 859 } | |
| 860 | |
| 861 int lengthInBytes() { | |
| 862 return _length() * _BYTES_PER_ELEMENT; | |
| 863 } | |
| 864 | |
| 865 static const int _BYTES_PER_ELEMENT = 2; | |
| 866 | |
| 867 static _Uint16Array _new(int length) native "Uint16Array_new"; | |
| 868 | |
| 869 int _getIndexed(int index) native "Uint16Array_getIndexed"; | |
| 870 int _setIndexed(int index, int value) native "Uint16Array_setIndexed"; | |
| 871 } | |
| 872 | |
| 873 | |
| 874 class _Int32Array extends _ByteArrayBase implements Int32List { | |
| 875 factory _Int32Array(int length) { | |
| 876 return _new(length); | |
| 877 } | |
| 878 | |
| 879 factory _Int32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 880 if (length == null) { | |
| 881 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 882 } | |
| 883 return new _Int32ArrayView(array, start, length); | |
| 884 } | |
| 885 | |
| 886 int operator[](int index) { | |
| 887 return _getIndexed(index); | |
| 888 } | |
| 889 | |
| 890 int operator[]=(int index, int value) { | |
| 891 _setIndexed(index, _toInt32(value)); | |
| 892 } | |
| 893 | |
| 894 Iterator<int> get iterator { | |
| 895 return new _ByteArrayIterator<int>(this); | |
| 896 } | |
| 897 | |
| 898 List<int> sublist(int start, [int end]) { | |
| 899 if (end == null) end = this.length; | |
| 900 int length = end - start; | |
| 901 _rangeCheck(this.length, start, length); | |
| 902 List<int> result = _new(length); | |
| 903 result.setRange(0, length, this, start); | |
| 904 return result; | |
| 905 } | |
| 906 | |
| 907 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 908 | |
| 909 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 910 if (from is _Int32Array) { | |
| 911 _setRange(start * _BYTES_PER_ELEMENT, | |
| 912 length * _BYTES_PER_ELEMENT, | |
| 913 from, | |
| 914 startFrom * _BYTES_PER_ELEMENT); | |
| 915 } else { | |
| 916 IterableMixinWorkaround.setRangeList( | |
| 917 this, start, length, from, startFrom); | |
| 918 } | |
| 919 } | |
| 920 | |
| 921 String toString() { | |
| 922 return Collections.collectionToString(this); | |
| 923 } | |
| 924 | |
| 925 int bytesPerElement() { | |
| 926 return _BYTES_PER_ELEMENT; | |
| 927 } | |
| 928 | |
| 929 int lengthInBytes() { | |
| 930 return _length() * _BYTES_PER_ELEMENT; | |
| 931 } | |
| 932 | |
| 933 static const int _BYTES_PER_ELEMENT = 4; | |
| 934 | |
| 935 static _Int32Array _new(int length) native "Int32Array_new"; | |
| 936 | |
| 937 | |
| 938 int _getIndexed(int index) native "Int32Array_getIndexed"; | |
| 939 int _setIndexed(int index, int value) native "Int32Array_setIndexed"; | |
| 940 } | |
| 941 | |
| 942 | |
| 943 class _Uint32Array extends _ByteArrayBase implements Uint32List { | |
| 944 factory _Uint32Array(int length) { | |
| 945 return _new(length); | |
| 946 } | |
| 947 | |
| 948 factory _Uint32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 949 if (length == null) { | |
| 950 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 951 } | |
| 952 return new _Uint32ArrayView(array, start, length); | |
| 953 } | |
| 954 | |
| 955 int operator[](int index) { | |
| 956 return _getIndexed(index); | |
| 957 } | |
| 958 | |
| 959 int operator[]=(int index, int value) { | |
| 960 _setIndexed(index, _toUint32(value)); | |
| 961 } | |
| 962 | |
| 963 Iterator<int> get iterator { | |
| 964 return new _ByteArrayIterator<int>(this); | |
| 965 } | |
| 966 | |
| 967 List<int> sublist(int start, [int end]) { | |
| 968 if (end == null) end = this.length; | |
| 969 int length = end - start; | |
| 970 _rangeCheck(this.length, start, length); | |
| 971 List<int> result = _new(length); | |
| 972 result.setRange(0, length, this, start); | |
| 973 return result; | |
| 974 } | |
| 975 | |
| 976 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 977 | |
| 978 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 979 if (from is _Uint32Array) { | |
| 980 _setRange(start * _BYTES_PER_ELEMENT, | |
| 981 length * _BYTES_PER_ELEMENT, | |
| 982 from, | |
| 983 startFrom * _BYTES_PER_ELEMENT); | |
| 984 } else { | |
| 985 IterableMixinWorkaround.setRangeList( | |
| 986 this, start, length, from, startFrom); | |
| 987 } | |
| 988 } | |
| 989 | |
| 990 String toString() { | |
| 991 return Collections.collectionToString(this); | |
| 992 } | |
| 993 | |
| 994 int bytesPerElement() { | |
| 995 return _BYTES_PER_ELEMENT; | |
| 996 } | |
| 997 | |
| 998 int lengthInBytes() { | |
| 999 return _length() * _BYTES_PER_ELEMENT; | |
| 1000 } | |
| 1001 | |
| 1002 static const int _BYTES_PER_ELEMENT = 4; | |
| 1003 | |
| 1004 static _Uint32Array _new(int length) native "Uint32Array_new"; | |
| 1005 | |
| 1006 int _getIndexed(int index) native "Uint32Array_getIndexed"; | |
| 1007 int _setIndexed(int index, int value) native "Uint32Array_setIndexed"; | |
| 1008 } | |
| 1009 | |
| 1010 | |
| 1011 class _Int64Array extends _ByteArrayBase implements Int64List { | |
| 1012 factory _Int64Array(int length) { | |
| 1013 return _new(length); | |
| 1014 } | |
| 1015 | |
| 1016 factory _Int64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 1017 if (length == null) { | |
| 1018 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 1019 } | |
| 1020 return new _Int64ArrayView(array, start, length); | |
| 1021 } | |
| 1022 | |
| 1023 int operator[](int index) { | |
| 1024 return _getIndexed(index); | |
| 1025 } | |
| 1026 | |
| 1027 int operator[]=(int index, int value) { | |
| 1028 _setIndexed(index, _toInt64(value)); | |
| 1029 } | |
| 1030 | |
| 1031 Iterator<int> get iterator { | |
| 1032 return new _ByteArrayIterator<int>(this); | |
| 1033 } | |
| 1034 | |
| 1035 List<int> sublist(int start, [int end]) { | |
| 1036 if (end == null) end = this.length; | |
| 1037 int length = end - start; | |
| 1038 _rangeCheck(this.length, start, length); | |
| 1039 List<int> result = _new(length); | |
| 1040 result.setRange(0, length, this, start); | |
| 1041 return result; | |
| 1042 } | |
| 1043 | |
| 1044 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1045 | |
| 1046 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1047 if (from is _Int64Array) { | |
| 1048 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1049 length * _BYTES_PER_ELEMENT, | |
| 1050 from, | |
| 1051 startFrom * _BYTES_PER_ELEMENT); | |
| 1052 } else { | |
| 1053 IterableMixinWorkaround.setRangeList( | |
| 1054 this, start, length, from, startFrom); | |
| 1055 } | |
| 1056 } | |
| 1057 | |
| 1058 String toString() { | |
| 1059 return Collections.collectionToString(this); | |
| 1060 } | |
| 1061 | |
| 1062 int bytesPerElement() { | |
| 1063 return _BYTES_PER_ELEMENT; | |
| 1064 } | |
| 1065 | |
| 1066 int lengthInBytes() { | |
| 1067 return _length() * _BYTES_PER_ELEMENT; | |
| 1068 } | |
| 1069 | |
| 1070 static const int _BYTES_PER_ELEMENT = 8; | |
| 1071 | |
| 1072 static _Int64Array _new(int length) native "Int64Array_new"; | |
| 1073 | |
| 1074 int _getIndexed(int index) native "Int64Array_getIndexed"; | |
| 1075 int _setIndexed(int index, int value) native "Int64Array_setIndexed"; | |
| 1076 } | |
| 1077 | |
| 1078 | |
| 1079 class _Uint64Array extends _ByteArrayBase implements Uint64List { | |
| 1080 factory _Uint64Array(int length) { | |
| 1081 return _new(length); | |
| 1082 } | |
| 1083 | |
| 1084 factory _Uint64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 1085 if (length == null) { | |
| 1086 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 1087 } | |
| 1088 return new _Uint64ArrayView(array, start, length); | |
| 1089 } | |
| 1090 | |
| 1091 int operator[](int index) { | |
| 1092 return _getIndexed(index); | |
| 1093 } | |
| 1094 | |
| 1095 int operator[]=(int index, int value) { | |
| 1096 _setIndexed(index, _toUint64(value)); | |
| 1097 } | |
| 1098 | |
| 1099 Iterator<int> get iterator { | |
| 1100 return new _ByteArrayIterator<int>(this); | |
| 1101 } | |
| 1102 | |
| 1103 List<int> sublist(int start, [int end]) { | |
| 1104 if (end == null) end = this.length; | |
| 1105 int length = end - start; | |
| 1106 _rangeCheck(this.length, start, length); | |
| 1107 List<int> result = _new(length); | |
| 1108 result.setRange(0, length, this, start); | |
| 1109 return result; | |
| 1110 } | |
| 1111 | |
| 1112 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1113 | |
| 1114 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1115 if (from is _Uint64Array) { | |
| 1116 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1117 length * _BYTES_PER_ELEMENT, | |
| 1118 from, | |
| 1119 startFrom * _BYTES_PER_ELEMENT); | |
| 1120 } else { | |
| 1121 IterableMixinWorkaround.setRangeList( | |
| 1122 this, start, length, from, startFrom); | |
| 1123 } | |
| 1124 } | |
| 1125 | |
| 1126 String toString() { | |
| 1127 return Collections.collectionToString(this); | |
| 1128 } | |
| 1129 | |
| 1130 int bytesPerElement() { | |
| 1131 return _BYTES_PER_ELEMENT; | |
| 1132 } | |
| 1133 | |
| 1134 int lengthInBytes() { | |
| 1135 return _length() * _BYTES_PER_ELEMENT; | |
| 1136 } | |
| 1137 | |
| 1138 static const int _BYTES_PER_ELEMENT = 8; | |
| 1139 | |
| 1140 static _Uint64Array _new(int length) native "Uint64Array_new"; | |
| 1141 | |
| 1142 int _getIndexed(int index) native "Uint64Array_getIndexed"; | |
| 1143 int _setIndexed(int index, int value) native "Uint64Array_setIndexed"; | |
| 1144 } | |
| 1145 | |
| 1146 | |
| 1147 class _Float32Array extends _ByteArrayBase implements Float32List { | |
| 1148 factory _Float32Array(int length) { | |
| 1149 return _new(length); | |
| 1150 } | |
| 1151 | |
| 1152 factory _Float32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 1153 if (length == null) { | |
| 1154 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 1155 } | |
| 1156 return new _Float32ArrayView(array, start, length); | |
| 1157 } | |
| 1158 | |
| 1159 double operator[](int index) { | |
| 1160 return _getIndexed(index); | |
| 1161 } | |
| 1162 | |
| 1163 int operator[]=(int index, double value) { | |
| 1164 _setIndexed(index, value); | |
| 1165 } | |
| 1166 | |
| 1167 Iterator<double> get iterator { | |
| 1168 return new _ByteArrayIterator<double>(this); | |
| 1169 } | |
| 1170 | |
| 1171 List<double> sublist(int start, [int end]) { | |
| 1172 if (end == null) end = this.length; | |
| 1173 int length = end - start; | |
| 1174 _rangeCheck(this.length, start, length); | |
| 1175 List<double> result = _new(length); | |
| 1176 result.setRange(0, length, this, start); | |
| 1177 return result; | |
| 1178 } | |
| 1179 | |
| 1180 List<double> getRange(int start, int length) => | |
| 1181 sublist(start, start + length); | |
| 1182 | |
| 1183 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 1184 if (from is _Float32Array) { | |
| 1185 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1186 length * _BYTES_PER_ELEMENT, | |
| 1187 from, | |
| 1188 startFrom * _BYTES_PER_ELEMENT); | |
| 1189 } else { | |
| 1190 IterableMixinWorkaround.setRangeList( | |
| 1191 this, start, length, from, startFrom); | |
| 1192 } | |
| 1193 } | |
| 1194 | |
| 1195 String toString() { | |
| 1196 return Collections.collectionToString(this); | |
| 1197 } | |
| 1198 | |
| 1199 int bytesPerElement() { | |
| 1200 return _BYTES_PER_ELEMENT; | |
| 1201 } | |
| 1202 | |
| 1203 int lengthInBytes() { | |
| 1204 return _length() * _BYTES_PER_ELEMENT; | |
| 1205 } | |
| 1206 | |
| 1207 static const int _BYTES_PER_ELEMENT = 4; | |
| 1208 | |
| 1209 static _Float32Array _new(int length) native "Float32Array_new"; | |
| 1210 | |
| 1211 double _getIndexed(int index) native "Float32Array_getIndexed"; | |
| 1212 int _setIndexed(int index, double value) native "Float32Array_setIndexed"; | |
| 1213 } | |
| 1214 | |
| 1215 | |
| 1216 class _Float64Array extends _ByteArrayBase implements Float64List { | |
| 1217 factory _Float64Array(int length) { | |
| 1218 return _new(length); | |
| 1219 } | |
| 1220 | |
| 1221 factory _Float64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 1222 if (length == null) { | |
| 1223 length = (array.lengthInBytes() - start) ~/ _BYTES_PER_ELEMENT; | |
| 1224 } | |
| 1225 return new _Float64ArrayView(array, start, length); | |
| 1226 } | |
| 1227 | |
| 1228 double operator[](int index) { | |
| 1229 return _getIndexed(index); | |
| 1230 } | |
| 1231 | |
| 1232 int operator[]=(int index, double value) { | |
| 1233 _setIndexed(index, value); | |
| 1234 } | |
| 1235 | |
| 1236 Iterator<double> get iterator { | |
| 1237 return new _ByteArrayIterator<double>(this); | |
| 1238 } | |
| 1239 | |
| 1240 List<double> sublist(int start, [int end]) { | |
| 1241 if (end == null) end = this.length; | |
| 1242 int length = end - start; | |
| 1243 _rangeCheck(this.length, start, length); | |
| 1244 List<double> result = _new(length); | |
| 1245 result.setRange(0, length, this, start); | |
| 1246 return result; | |
| 1247 } | |
| 1248 | |
| 1249 List<double> getRange(int start, int length) => | |
| 1250 sublist(start, start + length); | |
| 1251 | |
| 1252 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 1253 if (from is _Float64Array) { | |
| 1254 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1255 length * _BYTES_PER_ELEMENT, | |
| 1256 from, | |
| 1257 startFrom * _BYTES_PER_ELEMENT); | |
| 1258 } else { | |
| 1259 IterableMixinWorkaround.setRangeList( | |
| 1260 this, start, length, from, startFrom); | |
| 1261 } | |
| 1262 } | |
| 1263 | |
| 1264 String toString() { | |
| 1265 return Collections.collectionToString(this); | |
| 1266 } | |
| 1267 | |
| 1268 int bytesPerElement() { | |
| 1269 return _BYTES_PER_ELEMENT; | |
| 1270 } | |
| 1271 | |
| 1272 int lengthInBytes() { | |
| 1273 return _length() * _BYTES_PER_ELEMENT; | |
| 1274 } | |
| 1275 | |
| 1276 static const int _BYTES_PER_ELEMENT = 8; | |
| 1277 | |
| 1278 static _Float64Array _new(int length) native "Float64Array_new"; | |
| 1279 | |
| 1280 double _getIndexed(int index) native "Float64Array_getIndexed"; | |
| 1281 int _setIndexed(int index, double value) native "Float64Array_setIndexed"; | |
| 1282 } | |
| 1283 | |
| 1284 | |
| 1285 class _ExternalInt8Array extends _ByteArrayBase implements Int8List { | |
| 1286 int operator[](int index) { | |
| 1287 return _getIndexed(index); | |
| 1288 } | |
| 1289 | |
| 1290 int operator[]=(int index, int value) { | |
| 1291 _setIndexed(index, _toInt8(value)); | |
| 1292 } | |
| 1293 | |
| 1294 Iterator<int> get iterator { | |
| 1295 return new _ByteArrayIterator<int>(this); | |
| 1296 } | |
| 1297 | |
| 1298 List<int> sublist(int start, [int end]) { | |
| 1299 if (end == null) end = this.length; | |
| 1300 int length = end - start; | |
| 1301 _rangeCheck(this.length, start, length); | |
| 1302 List<int> result = new Int8List(length); | |
| 1303 result.setRange(0, length, this, start); | |
| 1304 return result; | |
| 1305 } | |
| 1306 | |
| 1307 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1308 | |
| 1309 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1310 if (from is _ExternalInt8Array) { | |
| 1311 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1312 length * _BYTES_PER_ELEMENT, | |
| 1313 from, | |
| 1314 startFrom * _BYTES_PER_ELEMENT); | |
| 1315 } else { | |
| 1316 IterableMixinWorkaround.setRangeList( | |
| 1317 this, start, length, from, startFrom); | |
| 1318 } | |
| 1319 } | |
| 1320 | |
| 1321 String toString() { | |
| 1322 return Collections.collectionToString(this); | |
| 1323 } | |
| 1324 | |
| 1325 int bytesPerElement() { | |
| 1326 return _BYTES_PER_ELEMENT; | |
| 1327 } | |
| 1328 | |
| 1329 int lengthInBytes() { | |
| 1330 return _length() * _BYTES_PER_ELEMENT; | |
| 1331 } | |
| 1332 | |
| 1333 static const int _BYTES_PER_ELEMENT = 1; | |
| 1334 | |
| 1335 int _getIndexed(int index) native "ExternalInt8Array_getIndexed"; | |
| 1336 int _setIndexed(int index, int value) native "ExternalInt8Array_setIndexed"; | |
| 1337 } | |
| 1338 | |
| 1339 | |
| 1340 class _ExternalUint8Array extends _ByteArrayBase implements Uint8List { | |
| 1341 int operator[](int index) { | |
| 1342 return _getIndexed(index); | |
| 1343 } | |
| 1344 | |
| 1345 int operator[]=(int index, int value) { | |
| 1346 _setIndexed(index, _toUint8(value)); | |
| 1347 } | |
| 1348 | |
| 1349 Iterator<int> get iterator { | |
| 1350 return new _ByteArrayIterator<int>(this); | |
| 1351 } | |
| 1352 | |
| 1353 List<int> sublist(int start, [int end]) { | |
| 1354 if (end == null) end = this.length; | |
| 1355 int length = end - start; | |
| 1356 _rangeCheck(this.length, start, length); | |
| 1357 List<int> result = new Uint8List(length); | |
| 1358 result.setRange(0, length, this, start); | |
| 1359 return result; | |
| 1360 } | |
| 1361 | |
| 1362 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1363 | |
| 1364 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1365 if (from is _ExternalUint8Array || from is _Uint8Array) { | |
| 1366 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1367 length * _BYTES_PER_ELEMENT, | |
| 1368 from, | |
| 1369 startFrom * _BYTES_PER_ELEMENT); | |
| 1370 } else { | |
| 1371 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom)
; | |
| 1372 } | |
| 1373 } | |
| 1374 | |
| 1375 String toString() { | |
| 1376 return Collections.collectionToString(this); | |
| 1377 } | |
| 1378 | |
| 1379 int bytesPerElement() { | |
| 1380 return _BYTES_PER_ELEMENT; | |
| 1381 } | |
| 1382 | |
| 1383 int lengthInBytes() { | |
| 1384 return _length() * _BYTES_PER_ELEMENT; | |
| 1385 } | |
| 1386 | |
| 1387 static const int _BYTES_PER_ELEMENT = 1; | |
| 1388 | |
| 1389 int _getIndexed(int index) native "ExternalUint8Array_getIndexed"; | |
| 1390 int _setIndexed(int index, int value) native "ExternalUint8Array_setIndexed"; | |
| 1391 } | |
| 1392 | |
| 1393 | |
| 1394 class _ExternalUint8ClampedArray | |
| 1395 extends _ByteArrayBase implements Uint8ClampedList { | |
| 1396 | |
| 1397 int operator[](int index) { | |
| 1398 return _getIndexed(index); | |
| 1399 } | |
| 1400 | |
| 1401 int operator[]=(int index, int value) { | |
| 1402 _setIndexed(index, _toClampedUint8(value)); | |
| 1403 } | |
| 1404 | |
| 1405 Iterator<int> get iterator { | |
| 1406 return new _ByteArrayIterator<int>(this); | |
| 1407 } | |
| 1408 | |
| 1409 List<int> sublist(int start, [int end]) { | |
| 1410 if (end == null) end = this.length; | |
| 1411 int length = end - start; | |
| 1412 _rangeCheck(this.length, start, length); | |
| 1413 List<int> result = new Uint8ClampedList(length); | |
| 1414 result.setRange(0, length, this, start); | |
| 1415 return result; | |
| 1416 } | |
| 1417 | |
| 1418 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1419 | |
| 1420 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1421 if (from is _ExternalUint8ClampedArray || from is _Uint8ClampedArray) { | |
| 1422 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1423 length * _BYTES_PER_ELEMENT, | |
| 1424 from, | |
| 1425 startFrom * _BYTES_PER_ELEMENT); | |
| 1426 } else { | |
| 1427 IterableMixinWorkaround.setRangeList( | |
| 1428 this, start, length, from, startFrom); | |
| 1429 } | |
| 1430 } | |
| 1431 | |
| 1432 String toString() { | |
| 1433 return Collections.collectionToString(this); | |
| 1434 } | |
| 1435 | |
| 1436 int bytesPerElement() { | |
| 1437 return _BYTES_PER_ELEMENT; | |
| 1438 } | |
| 1439 | |
| 1440 int lengthInBytes() { | |
| 1441 return _length() * _BYTES_PER_ELEMENT; | |
| 1442 } | |
| 1443 | |
| 1444 static const int _BYTES_PER_ELEMENT = 1; | |
| 1445 | |
| 1446 int _getIndexed(int index) native "ExternalUint8ClampedArray_getIndexed"; | |
| 1447 int _setIndexed(int index, int value) native "ExternalUint8ClampedArray_setInd
exed"; | |
| 1448 } | |
| 1449 | |
| 1450 | |
| 1451 class _ExternalInt16Array extends _ByteArrayBase implements Int16List { | |
| 1452 int operator[](int index) { | |
| 1453 return _getIndexed(index); | |
| 1454 } | |
| 1455 | |
| 1456 int operator[]=(int index, int value) { | |
| 1457 _setIndexed(index, _toInt16(value)); | |
| 1458 } | |
| 1459 | |
| 1460 Iterator<int> get iterator { | |
| 1461 return new _ByteArrayIterator<int>(this); | |
| 1462 } | |
| 1463 | |
| 1464 List<int> sublist(int start, [int end]) { | |
| 1465 if (end == null) end = this.length; | |
| 1466 int length = end - start; | |
| 1467 _rangeCheck(this.length, start, length); | |
| 1468 List<int> result = new Int16List(length); | |
| 1469 result.setRange(0, length, this, start); | |
| 1470 return result; | |
| 1471 } | |
| 1472 | |
| 1473 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1474 | |
| 1475 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1476 if (from is _ExternalInt16Array) { | |
| 1477 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1478 length * _BYTES_PER_ELEMENT, | |
| 1479 from, | |
| 1480 startFrom * _BYTES_PER_ELEMENT); | |
| 1481 } else { | |
| 1482 IterableMixinWorkaround.setRangeList( | |
| 1483 this, start, length, from, startFrom); | |
| 1484 } | |
| 1485 } | |
| 1486 | |
| 1487 String toString() { | |
| 1488 return Collections.collectionToString(this); | |
| 1489 } | |
| 1490 | |
| 1491 int bytesPerElement() { | |
| 1492 return _BYTES_PER_ELEMENT; | |
| 1493 } | |
| 1494 | |
| 1495 int lengthInBytes() { | |
| 1496 return _length() * _BYTES_PER_ELEMENT; | |
| 1497 } | |
| 1498 | |
| 1499 static const int _BYTES_PER_ELEMENT = 2; | |
| 1500 | |
| 1501 int _getIndexed(int index) native "ExternalInt16Array_getIndexed"; | |
| 1502 int _setIndexed(int index, int value) native "ExternalInt16Array_setIndexed"; | |
| 1503 } | |
| 1504 | |
| 1505 | |
| 1506 class _ExternalUint16Array extends _ByteArrayBase implements Uint16List { | |
| 1507 int operator[](int index) { | |
| 1508 return _getIndexed(index); | |
| 1509 } | |
| 1510 | |
| 1511 int operator[]=(int index, int value) { | |
| 1512 _setIndexed(index, _toUint16(value)); | |
| 1513 } | |
| 1514 | |
| 1515 Iterator<int> get iterator { | |
| 1516 return new _ByteArrayIterator<int>(this); | |
| 1517 } | |
| 1518 | |
| 1519 List<int> sublist(int start, [int end]) { | |
| 1520 if (end == null) end = this.length; | |
| 1521 int length = end - start; | |
| 1522 _rangeCheck(this.length, start, length); | |
| 1523 List<int> result = new Uint16List(length); | |
| 1524 result.setRange(0, length, this, start); | |
| 1525 return result; | |
| 1526 } | |
| 1527 | |
| 1528 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1529 | |
| 1530 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1531 if (from is _ExternalUint16Array) { | |
| 1532 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1533 length * _BYTES_PER_ELEMENT, | |
| 1534 from, | |
| 1535 startFrom * _BYTES_PER_ELEMENT); | |
| 1536 } else { | |
| 1537 IterableMixinWorkaround.setRangeList( | |
| 1538 this, start, length, from, startFrom); | |
| 1539 } | |
| 1540 } | |
| 1541 | |
| 1542 String toString() { | |
| 1543 return Collections.collectionToString(this); | |
| 1544 } | |
| 1545 | |
| 1546 int bytesPerElement() { | |
| 1547 return _BYTES_PER_ELEMENT; | |
| 1548 } | |
| 1549 | |
| 1550 int lengthInBytes() { | |
| 1551 return _length() * _BYTES_PER_ELEMENT; | |
| 1552 } | |
| 1553 | |
| 1554 static const int _BYTES_PER_ELEMENT = 2; | |
| 1555 | |
| 1556 int _getIndexed(int index) | |
| 1557 native "ExternalUint16Array_getIndexed"; | |
| 1558 int _setIndexed(int index, int value) | |
| 1559 native "ExternalUint16Array_setIndexed"; | |
| 1560 } | |
| 1561 | |
| 1562 | |
| 1563 class _ExternalInt32Array extends _ByteArrayBase implements Int32List { | |
| 1564 int operator[](int index) { | |
| 1565 return _getIndexed(index); | |
| 1566 } | |
| 1567 | |
| 1568 int operator[]=(int index, int value) { | |
| 1569 _setIndexed(index, _toInt32(value)); | |
| 1570 } | |
| 1571 | |
| 1572 Iterator<int> get iterator { | |
| 1573 return new _ByteArrayIterator<int>(this); | |
| 1574 } | |
| 1575 | |
| 1576 List<int> sublist(int start, [int end]) { | |
| 1577 if (end == null) end = this.length; | |
| 1578 int length = end - start; | |
| 1579 _rangeCheck(this.length, start, length); | |
| 1580 List<int> result = new Int32List(length); | |
| 1581 result.setRange(0, length, this, start); | |
| 1582 return result; | |
| 1583 } | |
| 1584 | |
| 1585 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1586 | |
| 1587 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1588 if (from is _ExternalInt32Array) { | |
| 1589 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1590 length * _BYTES_PER_ELEMENT, | |
| 1591 from, | |
| 1592 startFrom * _BYTES_PER_ELEMENT); | |
| 1593 } else { | |
| 1594 IterableMixinWorkaround.setRangeList( | |
| 1595 this, start, length, from, startFrom); | |
| 1596 } | |
| 1597 } | |
| 1598 | |
| 1599 String toString() { | |
| 1600 return Collections.collectionToString(this); | |
| 1601 } | |
| 1602 | |
| 1603 int bytesPerElement() { | |
| 1604 return _BYTES_PER_ELEMENT; | |
| 1605 } | |
| 1606 | |
| 1607 int lengthInBytes() { | |
| 1608 return _length() * _BYTES_PER_ELEMENT; | |
| 1609 } | |
| 1610 | |
| 1611 static const int _BYTES_PER_ELEMENT = 4; | |
| 1612 | |
| 1613 int _getIndexed(int index) | |
| 1614 native "ExternalInt32Array_getIndexed"; | |
| 1615 int _setIndexed(int index, int value) | |
| 1616 native "ExternalInt32Array_setIndexed"; | |
| 1617 } | |
| 1618 | |
| 1619 | |
| 1620 class _ExternalUint32Array extends _ByteArrayBase implements Uint32List { | |
| 1621 int operator[](int index) { | |
| 1622 return _getIndexed(index); | |
| 1623 } | |
| 1624 | |
| 1625 int operator[]=(int index, int value) { | |
| 1626 _setIndexed(index, _toUint32(value)); | |
| 1627 } | |
| 1628 | |
| 1629 Iterator<int> get iterator { | |
| 1630 return new _ByteArrayIterator<int>(this); | |
| 1631 } | |
| 1632 | |
| 1633 List<int> sublist(int start, [int end]) { | |
| 1634 if (end == null) end = this.length; | |
| 1635 int length = end - start; | |
| 1636 _rangeCheck(this.length, start, length); | |
| 1637 List<int> result = new Uint32List(length); | |
| 1638 result.setRange(0, length, this, start); | |
| 1639 return result; | |
| 1640 } | |
| 1641 | |
| 1642 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1643 | |
| 1644 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1645 if (from is _ExternalUint32Array) { | |
| 1646 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1647 length * _BYTES_PER_ELEMENT, | |
| 1648 from, | |
| 1649 startFrom * _BYTES_PER_ELEMENT); | |
| 1650 } else { | |
| 1651 IterableMixinWorkaround.setRangeList( | |
| 1652 this, start, length, from, startFrom); | |
| 1653 } | |
| 1654 } | |
| 1655 | |
| 1656 String toString() { | |
| 1657 return Collections.collectionToString(this); | |
| 1658 } | |
| 1659 | |
| 1660 int bytesPerElement() { | |
| 1661 return _BYTES_PER_ELEMENT; | |
| 1662 } | |
| 1663 | |
| 1664 int lengthInBytes() { | |
| 1665 return _length() * _BYTES_PER_ELEMENT; | |
| 1666 } | |
| 1667 | |
| 1668 static const int _BYTES_PER_ELEMENT = 4; | |
| 1669 | |
| 1670 int _getIndexed(int index) | |
| 1671 native "ExternalUint32Array_getIndexed"; | |
| 1672 int _setIndexed(int index, int value) | |
| 1673 native "ExternalUint32Array_setIndexed"; | |
| 1674 } | |
| 1675 | |
| 1676 | |
| 1677 class _ExternalInt64Array extends _ByteArrayBase implements Int64List { | |
| 1678 int operator[](int index) { | |
| 1679 return _getIndexed(index); | |
| 1680 } | |
| 1681 | |
| 1682 int operator[]=(int index, int value) { | |
| 1683 _setIndexed(index, _toInt64(value)); | |
| 1684 } | |
| 1685 | |
| 1686 Iterator<int> get iterator { | |
| 1687 return new _ByteArrayIterator<int>(this); | |
| 1688 } | |
| 1689 | |
| 1690 List<int> sublist(int start, [int end]) { | |
| 1691 if (end == null) end = this.length; | |
| 1692 int length = end - start; | |
| 1693 _rangeCheck(this.length, start, length); | |
| 1694 List<int> result = new Int64List(length); | |
| 1695 result.setRange(0, length, this, start); | |
| 1696 return result; | |
| 1697 } | |
| 1698 | |
| 1699 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1700 | |
| 1701 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1702 if (from is _ExternalInt64Array) { | |
| 1703 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1704 length * _BYTES_PER_ELEMENT, | |
| 1705 from, | |
| 1706 startFrom * _BYTES_PER_ELEMENT); | |
| 1707 } else { | |
| 1708 IterableMixinWorkaround.setRangeList( | |
| 1709 this, start, length, from, startFrom); | |
| 1710 } | |
| 1711 } | |
| 1712 | |
| 1713 String toString() { | |
| 1714 return Collections.collectionToString(this); | |
| 1715 } | |
| 1716 | |
| 1717 int bytesPerElement() { | |
| 1718 return _BYTES_PER_ELEMENT; | |
| 1719 } | |
| 1720 | |
| 1721 int lengthInBytes() { | |
| 1722 return _length() * _BYTES_PER_ELEMENT; | |
| 1723 } | |
| 1724 | |
| 1725 static const int _BYTES_PER_ELEMENT = 8; | |
| 1726 | |
| 1727 int _getIndexed(int index) | |
| 1728 native "ExternalInt64Array_getIndexed"; | |
| 1729 int _setIndexed(int index, int value) | |
| 1730 native "ExternalInt64Array_setIndexed"; | |
| 1731 } | |
| 1732 | |
| 1733 | |
| 1734 class _ExternalUint64Array extends _ByteArrayBase implements Uint64List { | |
| 1735 int operator[](int index) { | |
| 1736 return _getIndexed(index); | |
| 1737 } | |
| 1738 | |
| 1739 int operator[]=(int index, int value) { | |
| 1740 _setIndexed(index, _toUint64(value)); | |
| 1741 } | |
| 1742 | |
| 1743 Iterator<int> get iterator { | |
| 1744 return new _ByteArrayIterator<int>(this); | |
| 1745 } | |
| 1746 | |
| 1747 List<int> sublist(int start, [int end]) { | |
| 1748 if (end == null) end = this.length; | |
| 1749 int length = end - start; | |
| 1750 _rangeCheck(this.length, start, length); | |
| 1751 List<int> result = new Uint64List(length); | |
| 1752 result.setRange(0, length, this, start); | |
| 1753 return result; | |
| 1754 } | |
| 1755 | |
| 1756 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 1757 | |
| 1758 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1759 if (from is _ExternalUint64Array) { | |
| 1760 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1761 length * _BYTES_PER_ELEMENT, | |
| 1762 from, | |
| 1763 startFrom * _BYTES_PER_ELEMENT); | |
| 1764 } else { | |
| 1765 IterableMixinWorkaround.setRangeList( | |
| 1766 this, start, length, from, startFrom); | |
| 1767 } | |
| 1768 } | |
| 1769 | |
| 1770 String toString() { | |
| 1771 return Collections.collectionToString(this); | |
| 1772 } | |
| 1773 | |
| 1774 int bytesPerElement() { | |
| 1775 return _BYTES_PER_ELEMENT; | |
| 1776 } | |
| 1777 | |
| 1778 int lengthInBytes() { | |
| 1779 return _length() * _BYTES_PER_ELEMENT; | |
| 1780 } | |
| 1781 | |
| 1782 static const int _BYTES_PER_ELEMENT = 8; | |
| 1783 | |
| 1784 int _getIndexed(int index) | |
| 1785 native "ExternalUint64Array_getIndexed"; | |
| 1786 int _setIndexed(int index, int value) | |
| 1787 native "ExternalUint64Array_setIndexed"; | |
| 1788 } | |
| 1789 | |
| 1790 | |
| 1791 class _ExternalFloat32Array extends _ByteArrayBase implements Float32List { | |
| 1792 double operator[](int index) { | |
| 1793 return _getIndexed(index); | |
| 1794 } | |
| 1795 | |
| 1796 int operator[]=(int index, double value) { | |
| 1797 _setIndexed(index, value); | |
| 1798 } | |
| 1799 | |
| 1800 Iterator<double> get iterator { | |
| 1801 return new _ByteArrayIterator<double>(this); | |
| 1802 } | |
| 1803 | |
| 1804 List<double> sublist(int start, [int end]) { | |
| 1805 if (end == null) end = this.length; | |
| 1806 int length = end - start; | |
| 1807 _rangeCheck(this.length, start, length); | |
| 1808 List<double> result = new Float32List(length); | |
| 1809 result.setRange(0, length, this, start); | |
| 1810 return result; | |
| 1811 } | |
| 1812 | |
| 1813 List<double> getRange(int start, int length) => | |
| 1814 sublist(start, start + length); | |
| 1815 | |
| 1816 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 1817 if (from is _ExternalFloat32Array) { | |
| 1818 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1819 length * _BYTES_PER_ELEMENT, | |
| 1820 from, | |
| 1821 startFrom * _BYTES_PER_ELEMENT); | |
| 1822 } else { | |
| 1823 IterableMixinWorkaround.setRangeList( | |
| 1824 this, start, length, from, startFrom); | |
| 1825 } | |
| 1826 } | |
| 1827 | |
| 1828 String toString() { | |
| 1829 return Collections.collectionToString(this); | |
| 1830 } | |
| 1831 | |
| 1832 int bytesPerElement() { | |
| 1833 return _BYTES_PER_ELEMENT; | |
| 1834 } | |
| 1835 | |
| 1836 int lengthInBytes() { | |
| 1837 return _length() * _BYTES_PER_ELEMENT; | |
| 1838 } | |
| 1839 | |
| 1840 static const int _BYTES_PER_ELEMENT = 4; | |
| 1841 | |
| 1842 double _getIndexed(int index) | |
| 1843 native "ExternalFloat32Array_getIndexed"; | |
| 1844 int _setIndexed(int index, double value) | |
| 1845 native "ExternalFloat32Array_setIndexed"; | |
| 1846 } | |
| 1847 | |
| 1848 | |
| 1849 class _ExternalFloat64Array extends _ByteArrayBase implements Float64List { | |
| 1850 double operator[](int index) { | |
| 1851 return _getIndexed(index); | |
| 1852 } | |
| 1853 | |
| 1854 int operator[]=(int index, double value) { | |
| 1855 _setIndexed(index, value); | |
| 1856 } | |
| 1857 | |
| 1858 Iterator<double> get iterator { | |
| 1859 return new _ByteArrayIterator<double>(this); | |
| 1860 } | |
| 1861 | |
| 1862 List<double> sublist(int start, [int end]) { | |
| 1863 if (end == null) end = this.length; | |
| 1864 int length = end - start; | |
| 1865 _rangeCheck(this.length, start, length); | |
| 1866 List<double> result = new Float64List(length); | |
| 1867 result.setRange(0, length, this, start); | |
| 1868 return result; | |
| 1869 } | |
| 1870 | |
| 1871 List<double> getRange(int start, int length) => | |
| 1872 sublist(start, start + length); | |
| 1873 | |
| 1874 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 1875 if (from is _ExternalFloat64Array) { | |
| 1876 _setRange(start * _BYTES_PER_ELEMENT, | |
| 1877 length * _BYTES_PER_ELEMENT, | |
| 1878 from, | |
| 1879 startFrom * _BYTES_PER_ELEMENT); | |
| 1880 } else { | |
| 1881 IterableMixinWorkaround.setRangeList( | |
| 1882 this, start, length, from, startFrom); | |
| 1883 } | |
| 1884 } | |
| 1885 | |
| 1886 String toString() { | |
| 1887 return Collections.collectionToString(this); | |
| 1888 } | |
| 1889 | |
| 1890 int bytesPerElement() { | |
| 1891 return _BYTES_PER_ELEMENT; | |
| 1892 } | |
| 1893 | |
| 1894 int lengthInBytes() { | |
| 1895 return _length() * _BYTES_PER_ELEMENT; | |
| 1896 } | |
| 1897 | |
| 1898 static const int _BYTES_PER_ELEMENT = 8; | |
| 1899 | |
| 1900 double _getIndexed(int index) | |
| 1901 native "ExternalFloat64Array_getIndexed"; | |
| 1902 int _setIndexed(int index, double value) | |
| 1903 native "ExternalFloat64Array_setIndexed"; | |
| 1904 } | |
| 1905 | |
| 1906 | |
| 1907 class _ByteArrayIterator<E> implements Iterator<E> { | |
| 1908 final List<E> _array; | |
| 1909 final int _length; | |
| 1910 int _position; | |
| 1911 E _current; | |
| 1912 | |
| 1913 _ByteArrayIterator(List array) | |
| 1914 : _array = array, _length = array.length, _position = -1 { | |
| 1915 assert(array is _ByteArrayBase || array is _ByteArrayViewBase); | |
| 1916 } | |
| 1917 | |
| 1918 bool moveNext() { | |
| 1919 int nextPosition = _position + 1; | |
| 1920 if (nextPosition < _length) { | |
| 1921 _current = _array[nextPosition]; | |
| 1922 _position = nextPosition; | |
| 1923 return true; | |
| 1924 } | |
| 1925 _position = _length; | |
| 1926 _current = null; | |
| 1927 return false; | |
| 1928 } | |
| 1929 | |
| 1930 E get current => _current; | |
| 1931 } | |
| 1932 | |
| 1933 | |
| 1934 class _ByteArrayView implements ByteArray { | |
| 1935 _ByteArrayView(this._array, this._offset, this._length) { | |
| 1936 _rangeCheck(_array.lengthInBytes(), _offset, _length); | |
| 1937 } | |
| 1938 | |
| 1939 int lengthInBytes() { | |
| 1940 return _length; | |
| 1941 } | |
| 1942 | |
| 1943 ByteArray subByteArray([int start = 0, int length]) { | |
| 1944 if (start is! int) throw new ArgumentError("start is not an int"); | |
| 1945 if (length == null) { | |
| 1946 length = this.lengthInBytes() - start; | |
| 1947 } else if (length is! int) { | |
| 1948 throw new ArgumentError("length is not an int"); | |
| 1949 } | |
| 1950 return new _ByteArrayView(_array, _offset + start, length); | |
| 1951 } | |
| 1952 | |
| 1953 int getInt8(int byteOffset) { | |
| 1954 return _array._getInt8(_offset + byteOffset); | |
| 1955 } | |
| 1956 int setInt8(int byteOffset, int value) { | |
| 1957 return _array._setInt8(_offset + byteOffset, value); | |
| 1958 } | |
| 1959 | |
| 1960 int getUint8(int byteOffset) { | |
| 1961 return _array._getUint8(_offset + byteOffset); | |
| 1962 } | |
| 1963 int setUint8(int byteOffset, int value) { | |
| 1964 return _array._setUint8(_offset + byteOffset, value); | |
| 1965 } | |
| 1966 | |
| 1967 int getInt16(int byteOffset) { | |
| 1968 return _array._getInt16(_offset + byteOffset); | |
| 1969 } | |
| 1970 int setInt16(int byteOffset, int value) { | |
| 1971 return _array._setInt16(_offset + byteOffset, value); | |
| 1972 } | |
| 1973 | |
| 1974 int getUint16(int byteOffset) { | |
| 1975 return _array._getUint16(_offset + byteOffset); | |
| 1976 } | |
| 1977 int setUint16(int byteOffset, int value) { | |
| 1978 return _array._setUint16(_offset + byteOffset, value); | |
| 1979 } | |
| 1980 | |
| 1981 int getInt32(int byteOffset) { | |
| 1982 return _array._getInt32(_offset + byteOffset); | |
| 1983 } | |
| 1984 int setInt32(int byteOffset, int value) { | |
| 1985 return _array._setInt32(_offset + byteOffset, value); | |
| 1986 } | |
| 1987 | |
| 1988 int getUint32(int byteOffset) { | |
| 1989 return _array._getUint32(_offset + byteOffset); | |
| 1990 } | |
| 1991 int setUint32(int byteOffset, int value) { | |
| 1992 return _array._setUint32(_offset + byteOffset, value); | |
| 1993 } | |
| 1994 | |
| 1995 int getInt64(int byteOffset) { | |
| 1996 return _array._getInt64(_offset + byteOffset); | |
| 1997 } | |
| 1998 int setInt64(int byteOffset, int value) { | |
| 1999 return _array._setInt64(_offset + byteOffset, value); | |
| 2000 } | |
| 2001 | |
| 2002 int getUint64(int byteOffset) { | |
| 2003 return _array._getUint64(_offset + byteOffset); | |
| 2004 } | |
| 2005 int setUint64(int byteOffset, int value) { | |
| 2006 return _array._setUint64(_offset + byteOffset, value); | |
| 2007 } | |
| 2008 | |
| 2009 double getFloat32(int byteOffset) { | |
| 2010 return _array._getFloat32(_offset + byteOffset); | |
| 2011 } | |
| 2012 int setFloat32(int byteOffset, double value) { | |
| 2013 return _array._setFloat32(_offset + byteOffset, value); | |
| 2014 } | |
| 2015 | |
| 2016 double getFloat64(int byteOffset) { | |
| 2017 return _array._getFloat64(_offset + byteOffset); | |
| 2018 } | |
| 2019 int setFloat64(int byteOffset, double value) { | |
| 2020 return _array._setFloat64(_offset + byteOffset, value); | |
| 2021 } | |
| 2022 | |
| 2023 final _ByteArrayBase _array; | |
| 2024 final int _offset; | |
| 2025 final int _length; | |
| 2026 } | |
| 2027 | |
| 2028 | |
| 2029 // TODO(floitsch): extending the collection adds extra cost (because of type | |
| 2030 // parameters). Consider copying the functions from Collection into this class | |
| 2031 // and just implementing Collection<int>. | |
| 2032 class _ByteArrayViewBase extends Collection<int> { | |
| 2033 _ByteArrayViewBase(this._array, this._offset, this.length); | |
| 2034 | |
| 2035 num operator[](int index); | |
| 2036 | |
| 2037 // Methods implementing the Collection interface. | |
| 2038 | |
| 2039 void forEach(void f(element)) { | |
| 2040 var len = this.length; | |
| 2041 for (var i = 0; i < len; i++) { | |
| 2042 f(this[i]); | |
| 2043 } | |
| 2044 } | |
| 2045 | |
| 2046 bool get isEmpty { | |
| 2047 return this.length == 0; | |
| 2048 } | |
| 2049 | |
| 2050 // Methods implementing the List interface. | |
| 2051 | |
| 2052 set length(newLength) { | |
| 2053 throw new UnsupportedError( | |
| 2054 "Cannot resize a non-extendable array"); | |
| 2055 } | |
| 2056 | |
| 2057 void add(value) { | |
| 2058 throw new UnsupportedError( | |
| 2059 "Cannot add to a non-extendable array"); | |
| 2060 } | |
| 2061 | |
| 2062 void addLast(value) { | |
| 2063 throw new UnsupportedError( | |
| 2064 "Cannot add to a non-extendable array"); | |
| 2065 } | |
| 2066 | |
| 2067 void addAll(Iterable value) { | |
| 2068 throw new UnsupportedError( | |
| 2069 "Cannot add to a non-extendable array"); | |
| 2070 } | |
| 2071 | |
| 2072 void sort([int compare(var a, var b)]) { | |
| 2073 return IterableMixinWorkaround.sortList(this, compare); | |
| 2074 } | |
| 2075 | |
| 2076 int indexOf(element, [int start = 0]) { | |
| 2077 return IterableMixinWorkaround.indexOfList(this, element, start); | |
| 2078 } | |
| 2079 | |
| 2080 int lastIndexOf(element, [int start = null]) { | |
| 2081 return IterableMixinWorkaround.lastIndexOfList(this, element, start); | |
| 2082 } | |
| 2083 | |
| 2084 void clear() { | |
| 2085 throw new UnsupportedError( | |
| 2086 "Cannot remove from a non-extendable array"); | |
| 2087 } | |
| 2088 | |
| 2089 int removeLast() { | |
| 2090 throw new UnsupportedError( | |
| 2091 "Cannot remove from a non-extendable array"); | |
| 2092 } | |
| 2093 | |
| 2094 void insert(int index, int element) { | |
| 2095 throw new UnsupportedError( | |
| 2096 "Cannot add to a non-extendable array"); | |
| 2097 } | |
| 2098 | |
| 2099 int removeAt(int index) { | |
| 2100 throw new UnsupportedError( | |
| 2101 "Cannot remove from a non-extendable array"); | |
| 2102 } | |
| 2103 | |
| 2104 void remove(Object element) { | |
| 2105 throw new UnsupportedError( | |
| 2106 "Cannot remove from a non-extendable array"); | |
| 2107 } | |
| 2108 | |
| 2109 void removeAll(Iterable elements) { | |
| 2110 throw new UnsupportedError( | |
| 2111 "Cannot remove from a non-extendable array"); | |
| 2112 } | |
| 2113 | |
| 2114 void retainAll(Iterable elements) { | |
| 2115 throw new UnsupportedError( | |
| 2116 "Cannot remove from a non-extendable array"); | |
| 2117 } | |
| 2118 | |
| 2119 void removeWhere(bool test(int element)) { | |
| 2120 throw new UnsupportedError( | |
| 2121 "Cannot remove from a non-extendable array"); | |
| 2122 } | |
| 2123 | |
| 2124 void retainWhere(bool test(int element)) { | |
| 2125 throw new UnsupportedError( | |
| 2126 "Cannot remove from a non-extendable array"); | |
| 2127 } | |
| 2128 | |
| 2129 int get first { | |
| 2130 if (length > 0) return this[0]; | |
| 2131 throw new StateError("No elements"); | |
| 2132 } | |
| 2133 | |
| 2134 int get last { | |
| 2135 if (length > 0) return this[length - 1]; | |
| 2136 throw new StateError("No elements"); | |
| 2137 } | |
| 2138 | |
| 2139 int get single { | |
| 2140 if (length == 1) return this[0]; | |
| 2141 if (length == 0) throw new StateError("No elements"); | |
| 2142 throw new StateError("More than one element"); | |
| 2143 } | |
| 2144 | |
| 2145 void removeRange(int start, int length) { | |
| 2146 throw new UnsupportedError( | |
| 2147 "Cannot remove from a non-extendable array"); | |
| 2148 } | |
| 2149 | |
| 2150 void insertRange(int start, int length, [initialValue]) { | |
| 2151 throw new UnsupportedError( | |
| 2152 "Cannot add to a non-extendable array"); | |
| 2153 } | |
| 2154 | |
| 2155 Map<int, int> asMap() { | |
| 2156 return IterableMixinWorkaround.asMapList(this); | |
| 2157 } | |
| 2158 | |
| 2159 final ByteArray _array; | |
| 2160 final int _offset; | |
| 2161 final int length; | |
| 2162 } | |
| 2163 | |
| 2164 | |
| 2165 class _Int8ArrayView extends _ByteArrayViewBase implements Int8List { | |
| 2166 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2167 : super(array, _requireInteger(offsetInBytes), | |
| 2168 _requireIntegerOrNull( | |
| 2169 _length, | |
| 2170 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2171 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2172 } | |
| 2173 | |
| 2174 int operator[](int index) { | |
| 2175 if (index < 0 || index >= length) { | |
| 2176 String message = "$index must be in the range [0..$length)"; | |
| 2177 throw new RangeError(message); | |
| 2178 } | |
| 2179 return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2180 } | |
| 2181 | |
| 2182 void operator[]=(int index, int value) { | |
| 2183 if (index < 0 || index >= length) { | |
| 2184 String message = "$index must be in the range [0..$length)"; | |
| 2185 throw new RangeError(message); | |
| 2186 } | |
| 2187 _array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value)); | |
| 2188 } | |
| 2189 | |
| 2190 Iterator<int> get iterator { | |
| 2191 return new _ByteArrayIterator<int>(this); | |
| 2192 } | |
| 2193 | |
| 2194 List<int> sublist(int start, [int end]) { | |
| 2195 if (end == null) end = this.length; | |
| 2196 int length = end - start; | |
| 2197 _rangeCheck(this.length, start, length); | |
| 2198 List<int> result = new Int8List(length); | |
| 2199 result.setRange(0, length, this, start); | |
| 2200 return result; | |
| 2201 } | |
| 2202 | |
| 2203 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2204 | |
| 2205 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2206 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2207 } | |
| 2208 | |
| 2209 String toString() { | |
| 2210 return Collections.collectionToString(this); | |
| 2211 } | |
| 2212 | |
| 2213 int bytesPerElement() { | |
| 2214 return _BYTES_PER_ELEMENT; | |
| 2215 } | |
| 2216 | |
| 2217 int lengthInBytes() { | |
| 2218 return length * _BYTES_PER_ELEMENT; | |
| 2219 } | |
| 2220 | |
| 2221 ByteArray asByteArray([int start = 0, int length]) { | |
| 2222 if (length == null) { | |
| 2223 length = this.lengthInBytes(); | |
| 2224 } | |
| 2225 _rangeCheck(this.length, start, length); | |
| 2226 return _array.subByteArray(_offset + start, length); | |
| 2227 } | |
| 2228 | |
| 2229 static const int _BYTES_PER_ELEMENT = 1; | |
| 2230 } | |
| 2231 | |
| 2232 | |
| 2233 class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List { | |
| 2234 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2235 : super(array, _requireInteger(offsetInBytes), | |
| 2236 _requireIntegerOrNull( | |
| 2237 _length, | |
| 2238 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2239 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2240 } | |
| 2241 | |
| 2242 int operator[](int index) { | |
| 2243 if (index < 0 || index >= length) { | |
| 2244 String message = "$index must be in the range [0..$length)"; | |
| 2245 throw new RangeError(message); | |
| 2246 } | |
| 2247 return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2248 } | |
| 2249 | |
| 2250 void operator[]=(int index, int value) { | |
| 2251 if (index < 0 || index >= length) { | |
| 2252 String message = "$index must be in the range [0..$length)"; | |
| 2253 throw new RangeError(message); | |
| 2254 } | |
| 2255 _array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value)); | |
| 2256 } | |
| 2257 | |
| 2258 Iterator<int> get iterator { | |
| 2259 return new _ByteArrayIterator<int>(this); | |
| 2260 } | |
| 2261 | |
| 2262 List<int> sublist(int start, [int end]) { | |
| 2263 if (end == null) end = this.length; | |
| 2264 int length = end - start; | |
| 2265 _rangeCheck(this.length, start, length); | |
| 2266 List<int> result = new Uint8List(length); | |
| 2267 result.setRange(0, length, this, start); | |
| 2268 return result; | |
| 2269 } | |
| 2270 | |
| 2271 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2272 | |
| 2273 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2274 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2275 } | |
| 2276 | |
| 2277 String toString() { | |
| 2278 return Collections.collectionToString(this); | |
| 2279 } | |
| 2280 | |
| 2281 int bytesPerElement() { | |
| 2282 return _BYTES_PER_ELEMENT; | |
| 2283 } | |
| 2284 | |
| 2285 int lengthInBytes() { | |
| 2286 return length * _BYTES_PER_ELEMENT; | |
| 2287 } | |
| 2288 | |
| 2289 ByteArray asByteArray([int start = 0, int length]) { | |
| 2290 if (length == null) { | |
| 2291 length = this.lengthInBytes(); | |
| 2292 } | |
| 2293 _rangeCheck(this.length, start, length); | |
| 2294 return _array.subByteArray(_offset + start, length); | |
| 2295 } | |
| 2296 | |
| 2297 static const int _BYTES_PER_ELEMENT = 1; | |
| 2298 } | |
| 2299 | |
| 2300 | |
| 2301 class _Int16ArrayView extends _ByteArrayViewBase implements Int16List { | |
| 2302 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2303 : super(array, _requireInteger(offsetInBytes), | |
| 2304 _requireIntegerOrNull( | |
| 2305 _length, | |
| 2306 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2307 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2308 } | |
| 2309 | |
| 2310 int operator[](int index) { | |
| 2311 if (index < 0 || index >= length) { | |
| 2312 String message = "$index must be in the range [0..$length)"; | |
| 2313 throw new RangeError(message); | |
| 2314 } | |
| 2315 return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2316 } | |
| 2317 | |
| 2318 void operator[]=(int index, int value) { | |
| 2319 if (index < 0 || index >= length) { | |
| 2320 String message = "$index must be in the range [0..$length)"; | |
| 2321 throw new RangeError(message); | |
| 2322 } | |
| 2323 _array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value)); | |
| 2324 } | |
| 2325 | |
| 2326 Iterator<int> get iterator { | |
| 2327 return new _ByteArrayIterator<int>(this); | |
| 2328 } | |
| 2329 | |
| 2330 List<int> sublist(int start, [int end]) { | |
| 2331 if (end == null) end = this.length; | |
| 2332 int length = end - start; | |
| 2333 _rangeCheck(this.length, start, length); | |
| 2334 List<int> result = new Int16List(length); | |
| 2335 result.setRange(0, length, this, start); | |
| 2336 return result; | |
| 2337 } | |
| 2338 | |
| 2339 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2340 | |
| 2341 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2342 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2343 } | |
| 2344 | |
| 2345 String toString() { | |
| 2346 return Collections.collectionToString(this); | |
| 2347 } | |
| 2348 | |
| 2349 int bytesPerElement() { | |
| 2350 return _BYTES_PER_ELEMENT; | |
| 2351 } | |
| 2352 | |
| 2353 int lengthInBytes() { | |
| 2354 return length * _BYTES_PER_ELEMENT; | |
| 2355 } | |
| 2356 | |
| 2357 ByteArray asByteArray([int start = 0, int length]) { | |
| 2358 if (length == null) { | |
| 2359 length = this.lengthInBytes(); | |
| 2360 } | |
| 2361 _rangeCheck(this.length, start, length); | |
| 2362 return _array.subByteArray(_offset + start, length); | |
| 2363 } | |
| 2364 | |
| 2365 static const int _BYTES_PER_ELEMENT = 2; | |
| 2366 } | |
| 2367 | |
| 2368 | |
| 2369 class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List { | |
| 2370 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2371 : super(array, _requireInteger(offsetInBytes), | |
| 2372 _requireIntegerOrNull( | |
| 2373 _length, | |
| 2374 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2375 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2376 } | |
| 2377 | |
| 2378 int operator[](int index) { | |
| 2379 if (index < 0 || index >= length) { | |
| 2380 String message = "$index must be in the range [0..$length)"; | |
| 2381 throw new RangeError(message); | |
| 2382 } | |
| 2383 return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2384 } | |
| 2385 | |
| 2386 void operator[]=(int index, int value) { | |
| 2387 if (index < 0 || index >= length) { | |
| 2388 String message = "$index must be in the range [0..$length)"; | |
| 2389 throw new RangeError(message); | |
| 2390 } | |
| 2391 _array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value)); | |
| 2392 } | |
| 2393 | |
| 2394 Iterator<int> get iterator { | |
| 2395 return new _ByteArrayIterator<int>(this); | |
| 2396 } | |
| 2397 | |
| 2398 List<int> sublist(int start, [int end]) { | |
| 2399 if (end == null) end = this.length; | |
| 2400 int length = end - start; | |
| 2401 _rangeCheck(this.length, start, length); | |
| 2402 List<int> result = new Uint16List(length); | |
| 2403 result.setRange(0, length, this, start); | |
| 2404 return result; | |
| 2405 } | |
| 2406 | |
| 2407 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2408 | |
| 2409 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2410 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2411 } | |
| 2412 | |
| 2413 String toString() { | |
| 2414 return Collections.collectionToString(this); | |
| 2415 } | |
| 2416 | |
| 2417 int bytesPerElement() { | |
| 2418 return _BYTES_PER_ELEMENT; | |
| 2419 } | |
| 2420 | |
| 2421 int lengthInBytes() { | |
| 2422 return length * _BYTES_PER_ELEMENT; | |
| 2423 } | |
| 2424 | |
| 2425 ByteArray asByteArray([int start = 0, int length]) { | |
| 2426 if (length == null) { | |
| 2427 length = this.lengthInBytes(); | |
| 2428 } | |
| 2429 _rangeCheck(this.length, start, length); | |
| 2430 return _array.subByteArray(_offset + start, length); | |
| 2431 } | |
| 2432 | |
| 2433 static const int _BYTES_PER_ELEMENT = 2; | |
| 2434 } | |
| 2435 | |
| 2436 | |
| 2437 class _Int32ArrayView extends _ByteArrayViewBase implements Int32List { | |
| 2438 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2439 : super(array, _requireInteger(offsetInBytes), | |
| 2440 _requireIntegerOrNull( | |
| 2441 _length, | |
| 2442 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2443 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2444 } | |
| 2445 | |
| 2446 int operator[](int index) { | |
| 2447 if (index < 0 || index >= length) { | |
| 2448 String message = "$index must be in the range [0..$length)"; | |
| 2449 throw new RangeError(message); | |
| 2450 } | |
| 2451 return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2452 } | |
| 2453 | |
| 2454 void operator[]=(int index, int value) { | |
| 2455 if (index < 0 || index >= length) { | |
| 2456 String message = "$index must be in the range [0..$length)"; | |
| 2457 throw new RangeError(message); | |
| 2458 } | |
| 2459 _array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value)); | |
| 2460 } | |
| 2461 | |
| 2462 Iterator<int> get iterator { | |
| 2463 return new _ByteArrayIterator<int>(this); | |
| 2464 } | |
| 2465 | |
| 2466 List<int> sublist(int start, [int end]) { | |
| 2467 if (end == null) end = this.length; | |
| 2468 int length = end - start; | |
| 2469 _rangeCheck(this.length, start, length); | |
| 2470 List<int> result = new Int32List(length); | |
| 2471 result.setRange(0, length, this, start); | |
| 2472 return result; | |
| 2473 } | |
| 2474 | |
| 2475 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2476 | |
| 2477 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2478 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2479 } | |
| 2480 | |
| 2481 String toString() { | |
| 2482 return Collections.collectionToString(this); | |
| 2483 } | |
| 2484 | |
| 2485 int bytesPerElement() { | |
| 2486 return _BYTES_PER_ELEMENT; | |
| 2487 } | |
| 2488 | |
| 2489 int lengthInBytes() { | |
| 2490 return length * _BYTES_PER_ELEMENT; | |
| 2491 } | |
| 2492 | |
| 2493 ByteArray asByteArray([int start = 0, int length]) { | |
| 2494 if (length == null) { | |
| 2495 length = this.lengthInBytes(); | |
| 2496 } | |
| 2497 _rangeCheck(this.length, start, length); | |
| 2498 return _array.subByteArray(_offset + start, length); | |
| 2499 } | |
| 2500 | |
| 2501 static const int _BYTES_PER_ELEMENT = 4; | |
| 2502 } | |
| 2503 | |
| 2504 | |
| 2505 class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List { | |
| 2506 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2507 : super(array, _requireInteger(offsetInBytes), | |
| 2508 _requireIntegerOrNull( | |
| 2509 _length, | |
| 2510 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2511 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2512 } | |
| 2513 | |
| 2514 int operator[](int index) { | |
| 2515 if (index < 0 || index >= length) { | |
| 2516 String message = "$index must be in the range [0..$length)"; | |
| 2517 throw new RangeError(message); | |
| 2518 } | |
| 2519 return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2520 } | |
| 2521 | |
| 2522 void operator[]=(int index, int value) { | |
| 2523 if (index < 0 || index >= length) { | |
| 2524 String message = "$index must be in the range [0..$length)"; | |
| 2525 throw new RangeError(message); | |
| 2526 } | |
| 2527 _array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value)); | |
| 2528 } | |
| 2529 | |
| 2530 Iterator<int> get iterator { | |
| 2531 return new _ByteArrayIterator<int>(this); | |
| 2532 } | |
| 2533 | |
| 2534 List<int> sublist(int start, [int end]) { | |
| 2535 if (end == null) end = this.length; | |
| 2536 int length = end - start; | |
| 2537 _rangeCheck(this.length, start, length); | |
| 2538 List<int> result = new Uint32List(length); | |
| 2539 result.setRange(0, length, this, start); | |
| 2540 return result; | |
| 2541 } | |
| 2542 | |
| 2543 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2544 | |
| 2545 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2546 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2547 } | |
| 2548 | |
| 2549 String toString() { | |
| 2550 return Collections.collectionToString(this); | |
| 2551 } | |
| 2552 | |
| 2553 int bytesPerElement() { | |
| 2554 return _BYTES_PER_ELEMENT; | |
| 2555 } | |
| 2556 | |
| 2557 int lengthInBytes() { | |
| 2558 return length * _BYTES_PER_ELEMENT; | |
| 2559 } | |
| 2560 | |
| 2561 ByteArray asByteArray([int start = 0, int length]) { | |
| 2562 if (length == null) { | |
| 2563 length = this.lengthInBytes(); | |
| 2564 } | |
| 2565 _rangeCheck(this.length, start, length); | |
| 2566 return _array.subByteArray(_offset + start, length); | |
| 2567 } | |
| 2568 | |
| 2569 static const int _BYTES_PER_ELEMENT = 4; | |
| 2570 } | |
| 2571 | |
| 2572 | |
| 2573 class _Int64ArrayView extends _ByteArrayViewBase implements Int64List { | |
| 2574 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2575 : super(array, _requireInteger(offsetInBytes), | |
| 2576 _requireIntegerOrNull( | |
| 2577 _length, | |
| 2578 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2579 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2580 } | |
| 2581 | |
| 2582 int operator[](int index) { | |
| 2583 if (index < 0 || index >= length) { | |
| 2584 String message = "$index must be in the range [0..$length)"; | |
| 2585 throw new RangeError(message); | |
| 2586 } | |
| 2587 return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2588 } | |
| 2589 | |
| 2590 void operator[]=(int index, int value) { | |
| 2591 if (index < 0 || index >= length) { | |
| 2592 String message = "$index must be in the range [0..$length)"; | |
| 2593 throw new RangeError(message); | |
| 2594 } | |
| 2595 _array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value)); | |
| 2596 } | |
| 2597 | |
| 2598 Iterator<int> get iterator { | |
| 2599 return new _ByteArrayIterator<int>(this); | |
| 2600 } | |
| 2601 | |
| 2602 List<int> sublist(int start, [int end]) { | |
| 2603 if (end == null) end = this.length; | |
| 2604 int length = end - start; | |
| 2605 _rangeCheck(this.length, start, length); | |
| 2606 List<int> result = new Int64List(length); | |
| 2607 result.setRange(0, length, this, start); | |
| 2608 return result; | |
| 2609 } | |
| 2610 | |
| 2611 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2612 | |
| 2613 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2614 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2615 } | |
| 2616 | |
| 2617 String toString() { | |
| 2618 return Collections.collectionToString(this); | |
| 2619 } | |
| 2620 | |
| 2621 int bytesPerElement() { | |
| 2622 return _BYTES_PER_ELEMENT; | |
| 2623 } | |
| 2624 | |
| 2625 int lengthInBytes() { | |
| 2626 return length * _BYTES_PER_ELEMENT; | |
| 2627 } | |
| 2628 | |
| 2629 ByteArray asByteArray([int start = 0, int length]) { | |
| 2630 if (length == null) { | |
| 2631 length = this.lengthInBytes(); | |
| 2632 } | |
| 2633 _rangeCheck(this.length, start, length); | |
| 2634 return _array.subByteArray(_offset + start, length); | |
| 2635 } | |
| 2636 | |
| 2637 static const int _BYTES_PER_ELEMENT = 8; | |
| 2638 } | |
| 2639 | |
| 2640 | |
| 2641 class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List { | |
| 2642 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2643 : super(array, _requireInteger(offsetInBytes), | |
| 2644 _requireIntegerOrNull( | |
| 2645 _length, | |
| 2646 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2647 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2648 } | |
| 2649 | |
| 2650 int operator[](int index) { | |
| 2651 if (index < 0 || index >= length) { | |
| 2652 String message = "$index must be in the range [0..$length)"; | |
| 2653 throw new RangeError(message); | |
| 2654 } | |
| 2655 return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2656 } | |
| 2657 | |
| 2658 void operator[]=(int index, int value) { | |
| 2659 if (index < 0 || index >= length) { | |
| 2660 String message = "$index must be in the range [0..$length)"; | |
| 2661 throw new RangeError(message); | |
| 2662 } | |
| 2663 _array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value)); | |
| 2664 } | |
| 2665 | |
| 2666 Iterator<int> get iterator { | |
| 2667 return new _ByteArrayIterator<int>(this); | |
| 2668 } | |
| 2669 | |
| 2670 List<int> sublist(int start, [int end]) { | |
| 2671 if (end == null) end = this.length; | |
| 2672 int length = end - start; | |
| 2673 _rangeCheck(this.length, start, length); | |
| 2674 List<int> result = new Uint64List(length); | |
| 2675 result.setRange(0, length, this, start); | |
| 2676 return result; | |
| 2677 } | |
| 2678 | |
| 2679 List<int> getRange(int start, int length) => sublist(start, start + length); | |
| 2680 | |
| 2681 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2682 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2683 } | |
| 2684 | |
| 2685 String toString() { | |
| 2686 return Collections.collectionToString(this); | |
| 2687 } | |
| 2688 | |
| 2689 int bytesPerElement() { | |
| 2690 return _BYTES_PER_ELEMENT; | |
| 2691 } | |
| 2692 | |
| 2693 int lengthInBytes() { | |
| 2694 return length * _BYTES_PER_ELEMENT; | |
| 2695 } | |
| 2696 | |
| 2697 ByteArray asByteArray([int start = 0, int length]) { | |
| 2698 if (length == null) { | |
| 2699 length = this.lengthInBytes(); | |
| 2700 } | |
| 2701 _rangeCheck(this.length, start, length); | |
| 2702 return _array.subByteArray(_offset + start, length); | |
| 2703 } | |
| 2704 | |
| 2705 static const int _BYTES_PER_ELEMENT = 8; | |
| 2706 } | |
| 2707 | |
| 2708 | |
| 2709 class _Float32ArrayView extends _ByteArrayViewBase implements Float32List { | |
| 2710 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2711 : super(array, _requireInteger(offsetInBytes), | |
| 2712 _requireIntegerOrNull( | |
| 2713 _length, | |
| 2714 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2715 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2716 } | |
| 2717 | |
| 2718 double operator[](int index) { | |
| 2719 if (index < 0 || index >= length) { | |
| 2720 String message = "$index must be in the range [0..$length)"; | |
| 2721 throw new RangeError(message); | |
| 2722 } | |
| 2723 return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2724 } | |
| 2725 | |
| 2726 void operator[]=(int index, double value) { | |
| 2727 if (index < 0 || index >= length) { | |
| 2728 String message = "$index must be in the range [0..$length)"; | |
| 2729 throw new RangeError(message); | |
| 2730 } | |
| 2731 _array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value); | |
| 2732 } | |
| 2733 | |
| 2734 Iterator<double> get iterator { | |
| 2735 return new _ByteArrayIterator<double>(this); | |
| 2736 } | |
| 2737 | |
| 2738 List<double> sublist(int start, [int end]) { | |
| 2739 if (end == null) end = this.length; | |
| 2740 int length = end - start; | |
| 2741 _rangeCheck(this.length, start, length); | |
| 2742 List<double> result = new Float32List(length); | |
| 2743 result.setRange(0, length, this, start); | |
| 2744 return result; | |
| 2745 } | |
| 2746 | |
| 2747 List<double> getRange(int start, int length) => | |
| 2748 sublist(start, start + length); | |
| 2749 | |
| 2750 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 2751 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2752 } | |
| 2753 | |
| 2754 String toString() { | |
| 2755 return Collections.collectionToString(this); | |
| 2756 } | |
| 2757 | |
| 2758 int bytesPerElement() { | |
| 2759 return _BYTES_PER_ELEMENT; | |
| 2760 } | |
| 2761 | |
| 2762 int lengthInBytes() { | |
| 2763 return length * _BYTES_PER_ELEMENT; | |
| 2764 } | |
| 2765 | |
| 2766 ByteArray asByteArray([int start = 0, int length]) { | |
| 2767 if (length == null) { | |
| 2768 length = this.lengthInBytes(); | |
| 2769 } | |
| 2770 _rangeCheck(this.length, start, length); | |
| 2771 return _array.subByteArray(_offset + start, length); | |
| 2772 } | |
| 2773 | |
| 2774 static const int _BYTES_PER_ELEMENT = 4; | |
| 2775 } | |
| 2776 | |
| 2777 | |
| 2778 class _Float64ArrayView extends _ByteArrayViewBase implements Float64List { | |
| 2779 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length]) | |
| 2780 : super(array, _requireInteger(offsetInBytes), | |
| 2781 _requireIntegerOrNull( | |
| 2782 _length, | |
| 2783 ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) { | |
| 2784 _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT); | |
| 2785 } | |
| 2786 | |
| 2787 double operator[](int index) { | |
| 2788 if (index < 0 || index >= length) { | |
| 2789 String message = "$index must be in the range [0..$length)"; | |
| 2790 throw new RangeError(message); | |
| 2791 } | |
| 2792 return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT)); | |
| 2793 } | |
| 2794 | |
| 2795 void operator[]=(int index, double value) { | |
| 2796 if (index < 0 || index >= length) { | |
| 2797 String message = "$index must be in the range [0..$length)"; | |
| 2798 throw new RangeError(message); | |
| 2799 } | |
| 2800 _array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value); | |
| 2801 } | |
| 2802 | |
| 2803 Iterator<double> get iterator { | |
| 2804 return new _ByteArrayIterator<double>(this); | |
| 2805 } | |
| 2806 | |
| 2807 List<double> sublist(int start, [int end]) { | |
| 2808 if (end == null) end = this.length; | |
| 2809 int length = end - start; | |
| 2810 _rangeCheck(this.length, start, length); | |
| 2811 List<double> result = new Float64List(length); | |
| 2812 result.setRange(0, length, this, start); | |
| 2813 return result; | |
| 2814 } | |
| 2815 | |
| 2816 List<double> getRange(int start, int length) => | |
| 2817 sublist(start, start + length); | |
| 2818 | |
| 2819 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 2820 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); | |
| 2821 } | |
| 2822 | |
| 2823 String toString() { | |
| 2824 return Collections.collectionToString(this); | |
| 2825 } | |
| 2826 | |
| 2827 int bytesPerElement() { | |
| 2828 return _BYTES_PER_ELEMENT; | |
| 2829 } | |
| 2830 | |
| 2831 int lengthInBytes() { | |
| 2832 return length * _BYTES_PER_ELEMENT; | |
| 2833 } | |
| 2834 | |
| 2835 ByteArray asByteArray([int start = 0, int length]) { | |
| 2836 if (length == null) { | |
| 2837 length = this.lengthInBytes(); | |
| 2838 } | |
| 2839 _rangeCheck(this.length, start, length); | |
| 2840 return _array.subByteArray(_offset + start, length); | |
| 2841 } | |
| 2842 | |
| 2843 static const int _BYTES_PER_ELEMENT = 8; | |
| 2844 } | |
| OLD | NEW |