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