| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // patch classes for Int8List ..... Float64List and ByteData implementations. | 5 // patch classes for Int8List ..... Float64List and ByteData implementations. |
| 6 | 6 |
| 7 patch class Int8List { | 7 patch class Int8List { |
| 8 /* patch */ factory Int8List(int length) { | 8 /* patch */ factory Int8List(int length) { |
| 9 return new _Int8Array(length); | 9 return new _Int8Array(length); |
| 10 } | 10 } |
| (...skipping 2307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2318 class _Int16ArrayView extends _TypedListView implements Int16List { | 2318 class _Int16ArrayView extends _TypedListView implements Int16List { |
| 2319 // Constructor. | 2319 // Constructor. |
| 2320 _Int16ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2320 _Int16ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2321 : super(buffer, _offsetInBytes, | 2321 : super(buffer, _offsetInBytes, |
| 2322 _defaultIfNull(_length, | 2322 _defaultIfNull(_length, |
| 2323 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2323 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2324 Int16List.BYTES_PER_ELEMENT))) { | 2324 Int16List.BYTES_PER_ELEMENT))) { |
| 2325 _rangeCheck(buffer.lengthInBytes, | 2325 _rangeCheck(buffer.lengthInBytes, |
| 2326 offsetInBytes, | 2326 offsetInBytes, |
| 2327 length * Int16List.BYTES_PER_ELEMENT); | 2327 length * Int16List.BYTES_PER_ELEMENT); |
| 2328 _offsetAlignmentCheck(_offsetInBytes, Int16List.BYTES_PER_ELEMENT); |
| 2328 } | 2329 } |
| 2329 | 2330 |
| 2330 | 2331 |
| 2331 // Method(s) implementing List interface. | 2332 // Method(s) implementing List interface. |
| 2332 | 2333 |
| 2333 int operator[](int index) { | 2334 int operator[](int index) { |
| 2334 if (index < 0 || index >= length) { | 2335 if (index < 0 || index >= length) { |
| 2335 _throwRangeError(index, length); | 2336 _throwRangeError(index, length); |
| 2336 } | 2337 } |
| 2337 return _typedData._getInt16(offsetInBytes + | 2338 return _typedData._getInt16(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2369 class _Uint16ArrayView extends _TypedListView implements Uint16List { | 2370 class _Uint16ArrayView extends _TypedListView implements Uint16List { |
| 2370 // Constructor. | 2371 // Constructor. |
| 2371 _Uint16ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2372 _Uint16ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2372 : super(buffer, _offsetInBytes, | 2373 : super(buffer, _offsetInBytes, |
| 2373 _defaultIfNull(_length, | 2374 _defaultIfNull(_length, |
| 2374 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2375 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2375 Uint16List.BYTES_PER_ELEMENT))) { | 2376 Uint16List.BYTES_PER_ELEMENT))) { |
| 2376 _rangeCheck(buffer.lengthInBytes, | 2377 _rangeCheck(buffer.lengthInBytes, |
| 2377 offsetInBytes, | 2378 offsetInBytes, |
| 2378 length * Uint16List.BYTES_PER_ELEMENT); | 2379 length * Uint16List.BYTES_PER_ELEMENT); |
| 2380 _offsetAlignmentCheck(_offsetInBytes, Uint16List.BYTES_PER_ELEMENT); |
| 2379 } | 2381 } |
| 2380 | 2382 |
| 2381 | 2383 |
| 2382 // Method(s) implementing List interface. | 2384 // Method(s) implementing List interface. |
| 2383 | 2385 |
| 2384 int operator[](int index) { | 2386 int operator[](int index) { |
| 2385 if (index < 0 || index >= length) { | 2387 if (index < 0 || index >= length) { |
| 2386 _throwRangeError(index, length); | 2388 _throwRangeError(index, length); |
| 2387 } | 2389 } |
| 2388 return _typedData._getUint16(offsetInBytes + | 2390 return _typedData._getUint16(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 class _Int32ArrayView extends _TypedListView implements Int32List { | 2422 class _Int32ArrayView extends _TypedListView implements Int32List { |
| 2421 // Constructor. | 2423 // Constructor. |
| 2422 _Int32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2424 _Int32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2423 : super(buffer, _offsetInBytes, | 2425 : super(buffer, _offsetInBytes, |
| 2424 _defaultIfNull(_length, | 2426 _defaultIfNull(_length, |
| 2425 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2427 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2426 Int32List.BYTES_PER_ELEMENT))) { | 2428 Int32List.BYTES_PER_ELEMENT))) { |
| 2427 _rangeCheck(buffer.lengthInBytes, | 2429 _rangeCheck(buffer.lengthInBytes, |
| 2428 offsetInBytes, | 2430 offsetInBytes, |
| 2429 length * Int32List.BYTES_PER_ELEMENT); | 2431 length * Int32List.BYTES_PER_ELEMENT); |
| 2432 _offsetAlignmentCheck(_offsetInBytes, Int32List.BYTES_PER_ELEMENT); |
| 2430 } | 2433 } |
| 2431 | 2434 |
| 2432 | 2435 |
| 2433 // Method(s) implementing List interface. | 2436 // Method(s) implementing List interface. |
| 2434 | 2437 |
| 2435 int operator[](int index) { | 2438 int operator[](int index) { |
| 2436 if (index < 0 || index >= length) { | 2439 if (index < 0 || index >= length) { |
| 2437 _throwRangeError(index, length); | 2440 _throwRangeError(index, length); |
| 2438 } | 2441 } |
| 2439 return _typedData._getInt32(offsetInBytes + | 2442 return _typedData._getInt32(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2471 class _Uint32ArrayView extends _TypedListView implements Uint32List { | 2474 class _Uint32ArrayView extends _TypedListView implements Uint32List { |
| 2472 // Constructor. | 2475 // Constructor. |
| 2473 _Uint32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2476 _Uint32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2474 : super(buffer, _offsetInBytes, | 2477 : super(buffer, _offsetInBytes, |
| 2475 _defaultIfNull(_length, | 2478 _defaultIfNull(_length, |
| 2476 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2479 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2477 Uint32List.BYTES_PER_ELEMENT))) { | 2480 Uint32List.BYTES_PER_ELEMENT))) { |
| 2478 _rangeCheck(buffer.lengthInBytes, | 2481 _rangeCheck(buffer.lengthInBytes, |
| 2479 offsetInBytes, | 2482 offsetInBytes, |
| 2480 length * Uint32List.BYTES_PER_ELEMENT); | 2483 length * Uint32List.BYTES_PER_ELEMENT); |
| 2484 _offsetAlignmentCheck(_offsetInBytes, Uint32List.BYTES_PER_ELEMENT); |
| 2481 } | 2485 } |
| 2482 | 2486 |
| 2483 | 2487 |
| 2484 // Method(s) implementing List interface. | 2488 // Method(s) implementing List interface. |
| 2485 | 2489 |
| 2486 int operator[](int index) { | 2490 int operator[](int index) { |
| 2487 if (index < 0 || index >= length) { | 2491 if (index < 0 || index >= length) { |
| 2488 _throwRangeError(index, length); | 2492 _throwRangeError(index, length); |
| 2489 } | 2493 } |
| 2490 return _typedData._getUint32(offsetInBytes + | 2494 return _typedData._getUint32(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2522 class _Int64ArrayView extends _TypedListView implements Int64List { | 2526 class _Int64ArrayView extends _TypedListView implements Int64List { |
| 2523 // Constructor. | 2527 // Constructor. |
| 2524 _Int64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2528 _Int64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2525 : super(buffer, _offsetInBytes, | 2529 : super(buffer, _offsetInBytes, |
| 2526 _defaultIfNull(_length, | 2530 _defaultIfNull(_length, |
| 2527 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2531 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2528 Int64List.BYTES_PER_ELEMENT))) { | 2532 Int64List.BYTES_PER_ELEMENT))) { |
| 2529 _rangeCheck(buffer.lengthInBytes, | 2533 _rangeCheck(buffer.lengthInBytes, |
| 2530 offsetInBytes, | 2534 offsetInBytes, |
| 2531 length * Int64List.BYTES_PER_ELEMENT); | 2535 length * Int64List.BYTES_PER_ELEMENT); |
| 2536 _offsetAlignmentCheck(_offsetInBytes, Int64List.BYTES_PER_ELEMENT); |
| 2532 } | 2537 } |
| 2533 | 2538 |
| 2534 | 2539 |
| 2535 // Method(s) implementing List interface. | 2540 // Method(s) implementing List interface. |
| 2536 | 2541 |
| 2537 int operator[](int index) { | 2542 int operator[](int index) { |
| 2538 if (index < 0 || index >= length) { | 2543 if (index < 0 || index >= length) { |
| 2539 _throwRangeError(index, length); | 2544 _throwRangeError(index, length); |
| 2540 } | 2545 } |
| 2541 return _typedData._getInt64(offsetInBytes + | 2546 return _typedData._getInt64(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2573 class _Uint64ArrayView extends _TypedListView implements Uint64List { | 2578 class _Uint64ArrayView extends _TypedListView implements Uint64List { |
| 2574 // Constructor. | 2579 // Constructor. |
| 2575 _Uint64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2580 _Uint64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2576 : super(buffer, _offsetInBytes, | 2581 : super(buffer, _offsetInBytes, |
| 2577 _defaultIfNull(_length, | 2582 _defaultIfNull(_length, |
| 2578 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2583 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2579 Uint64List.BYTES_PER_ELEMENT))) { | 2584 Uint64List.BYTES_PER_ELEMENT))) { |
| 2580 _rangeCheck(buffer.lengthInBytes, | 2585 _rangeCheck(buffer.lengthInBytes, |
| 2581 offsetInBytes, | 2586 offsetInBytes, |
| 2582 length * Uint64List.BYTES_PER_ELEMENT); | 2587 length * Uint64List.BYTES_PER_ELEMENT); |
| 2588 _offsetAlignmentCheck(_offsetInBytes, Uint64List.BYTES_PER_ELEMENT); |
| 2583 } | 2589 } |
| 2584 | 2590 |
| 2585 | 2591 |
| 2586 // Method(s) implementing List interface. | 2592 // Method(s) implementing List interface. |
| 2587 | 2593 |
| 2588 int operator[](int index) { | 2594 int operator[](int index) { |
| 2589 if (index < 0 || index >= length) { | 2595 if (index < 0 || index >= length) { |
| 2590 _throwRangeError(index, length); | 2596 _throwRangeError(index, length); |
| 2591 } | 2597 } |
| 2592 return _typedData._getUint64(offsetInBytes + | 2598 return _typedData._getUint64(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2624 class _Float32ArrayView extends _TypedListView implements Float32List { | 2630 class _Float32ArrayView extends _TypedListView implements Float32List { |
| 2625 // Constructor. | 2631 // Constructor. |
| 2626 _Float32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2632 _Float32ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2627 : super(buffer, _offsetInBytes, | 2633 : super(buffer, _offsetInBytes, |
| 2628 _defaultIfNull(_length, | 2634 _defaultIfNull(_length, |
| 2629 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2635 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2630 Float32List.BYTES_PER_ELEMENT))) { | 2636 Float32List.BYTES_PER_ELEMENT))) { |
| 2631 _rangeCheck(buffer.lengthInBytes, | 2637 _rangeCheck(buffer.lengthInBytes, |
| 2632 offsetInBytes, | 2638 offsetInBytes, |
| 2633 length * Float32List.BYTES_PER_ELEMENT); | 2639 length * Float32List.BYTES_PER_ELEMENT); |
| 2640 _offsetAlignmentCheck(_offsetInBytes, Float32List.BYTES_PER_ELEMENT); |
| 2634 } | 2641 } |
| 2635 | 2642 |
| 2636 | 2643 |
| 2637 // Method(s) implementing List interface. | 2644 // Method(s) implementing List interface. |
| 2638 | 2645 |
| 2639 double operator[](int index) { | 2646 double operator[](int index) { |
| 2640 if (index < 0 || index >= length) { | 2647 if (index < 0 || index >= length) { |
| 2641 _throwRangeError(index, length); | 2648 _throwRangeError(index, length); |
| 2642 } | 2649 } |
| 2643 return _typedData._getFloat32(offsetInBytes + | 2650 return _typedData._getFloat32(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2675 class _Float64ArrayView extends _TypedListView implements Float64List { | 2682 class _Float64ArrayView extends _TypedListView implements Float64List { |
| 2676 // Constructor. | 2683 // Constructor. |
| 2677 _Float64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2684 _Float64ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2678 : super(buffer, _offsetInBytes, | 2685 : super(buffer, _offsetInBytes, |
| 2679 _defaultIfNull(_length, | 2686 _defaultIfNull(_length, |
| 2680 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2687 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2681 Float64List.BYTES_PER_ELEMENT))) { | 2688 Float64List.BYTES_PER_ELEMENT))) { |
| 2682 _rangeCheck(buffer.lengthInBytes, | 2689 _rangeCheck(buffer.lengthInBytes, |
| 2683 offsetInBytes, | 2690 offsetInBytes, |
| 2684 length * Float64List.BYTES_PER_ELEMENT); | 2691 length * Float64List.BYTES_PER_ELEMENT); |
| 2692 _offsetAlignmentCheck(_offsetInBytes, Float64List.BYTES_PER_ELEMENT); |
| 2685 } | 2693 } |
| 2686 | 2694 |
| 2687 | 2695 |
| 2688 // Method(s) implementing List interface. | 2696 // Method(s) implementing List interface. |
| 2689 | 2697 |
| 2690 double operator[](int index) { | 2698 double operator[](int index) { |
| 2691 if (index < 0 || index >= length) { | 2699 if (index < 0 || index >= length) { |
| 2692 _throwRangeError(index, length); | 2700 _throwRangeError(index, length); |
| 2693 } | 2701 } |
| 2694 return _typedData._getFloat64(offsetInBytes + | 2702 return _typedData._getFloat64(offsetInBytes + |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2726 class _Float32x4ArrayView extends _TypedListView implements Float32x4List { | 2734 class _Float32x4ArrayView extends _TypedListView implements Float32x4List { |
| 2727 // Constructor. | 2735 // Constructor. |
| 2728 _Float32x4ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) | 2736 _Float32x4ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length]) |
| 2729 : super(buffer, _offsetInBytes, | 2737 : super(buffer, _offsetInBytes, |
| 2730 _defaultIfNull(_length, | 2738 _defaultIfNull(_length, |
| 2731 ((buffer.lengthInBytes - _offsetInBytes) ~/ | 2739 ((buffer.lengthInBytes - _offsetInBytes) ~/ |
| 2732 Float32x4List.BYTES_PER_ELEMENT))) { | 2740 Float32x4List.BYTES_PER_ELEMENT))) { |
| 2733 _rangeCheck(buffer.lengthInBytes, | 2741 _rangeCheck(buffer.lengthInBytes, |
| 2734 offsetInBytes, | 2742 offsetInBytes, |
| 2735 length * Float32x4List.BYTES_PER_ELEMENT); | 2743 length * Float32x4List.BYTES_PER_ELEMENT); |
| 2744 _offsetAlignmentCheck(_offsetInBytes, Float32x4List.BYTES_PER_ELEMENT); |
| 2736 } | 2745 } |
| 2737 | 2746 |
| 2738 | 2747 |
| 2739 // Method(s) implementing List interface. | 2748 // Method(s) implementing List interface. |
| 2740 | 2749 |
| 2741 Float32x4 operator[](int index) { | 2750 Float32x4 operator[](int index) { |
| 2742 if (index < 0 || index >= length) { | 2751 if (index < 0 || index >= length) { |
| 2743 _throwRangeError(index, length); | 2752 _throwRangeError(index, length); |
| 2744 } | 2753 } |
| 2745 return _typedData._getFloat32x4(offsetInBytes + | 2754 return _typedData._getFloat32x4(offsetInBytes + |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3118 } | 3127 } |
| 3119 if (start < 0) { | 3128 if (start < 0) { |
| 3120 throw new RangeError.value(start); | 3129 throw new RangeError.value(start); |
| 3121 } | 3130 } |
| 3122 if (start + length > listLength) { | 3131 if (start + length > listLength) { |
| 3123 throw new RangeError.value(start + length); | 3132 throw new RangeError.value(start + length); |
| 3124 } | 3133 } |
| 3125 } | 3134 } |
| 3126 | 3135 |
| 3127 | 3136 |
| 3137 void _offsetAlignmentCheck(int offset, int alignment) { |
| 3138 if ((offset % alignment) != 0) { |
| 3139 throw new RangeError('Offset ($offset) must be a multiple of ' |
| 3140 'BYTES_PER_ELEMENT ($alignment)'); |
| 3141 } |
| 3142 } |
| 3143 |
| 3144 |
| 3128 int _defaultIfNull(object, value) { | 3145 int _defaultIfNull(object, value) { |
| 3129 if (object == null) { | 3146 if (object == null) { |
| 3130 return value; | 3147 return value; |
| 3131 } | 3148 } |
| 3132 return object; | 3149 return object; |
| 3133 } | 3150 } |
| 3134 | 3151 |
| 3135 | 3152 |
| 3136 void _throwRangeError(int index, int length) { | 3153 void _throwRangeError(int index, int length) { |
| 3137 String message = "$index must be in the range [0..$length)"; | 3154 String message = "$index must be in the range [0..$length)"; |
| 3138 throw new RangeError(message); | 3155 throw new RangeError(message); |
| 3139 } | 3156 } |
| OLD | NEW |