Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: runtime/lib/typeddata.dart

Issue 13529005: Fix view creation for byte-size types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix checked mode problems Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/typed_data_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 271 }
272 272
273 /* patch */ factory ByteData.transferable(int length) { 273 /* patch */ factory ByteData.transferable(int length) {
274 var list = new _Uint8Array.transferable(length); 274 var list = new _Uint8Array.transferable(length);
275 return new _ByteDataView(list.buffer, 0, length); 275 return new _ByteDataView(list.buffer, 0, length);
276 } 276 }
277 277
278 /* patch */ factory ByteData.view(ByteBuffer buffer, 278 /* patch */ factory ByteData.view(ByteBuffer buffer,
279 [int offsetInBytes = 0, int length]) { 279 [int offsetInBytes = 0, int length]) {
280 if (length == null) { 280 if (length == null) {
281 length = buffer.lengthInBytes; 281 length = buffer.lengthInBytes - offsetInBytes;
282 } 282 }
283 return new _ByteDataView(buffer, offsetInBytes, length); 283 return new _ByteDataView(buffer, offsetInBytes, length);
284 } 284 }
285 } 285 }
286 286
287 287
288 // Based class for _TypedList that provides common methods for implementing 288 // Based class for _TypedList that provides common methods for implementing
289 // the collection and list interfaces. 289 // the collection and list interfaces.
290 290
291 abstract class _TypedListBase { 291 abstract class _TypedListBase {
(...skipping 13 matching lines...) Expand all
305 305
306 String join([String separator]) { 306 String join([String separator]) {
307 return IterableMixinWorkaround.join(this, separator); 307 return IterableMixinWorkaround.join(this, separator);
308 } 308 }
309 309
310 dynamic reduce(dynamic initialValue, 310 dynamic reduce(dynamic initialValue,
311 dynamic combine(dynamic initialValue, element)) { 311 dynamic combine(dynamic initialValue, element)) {
312 return IterableMixinWorkaround.reduce(this, initialValue, combine); 312 return IterableMixinWorkaround.reduce(this, initialValue, combine);
313 } 313 }
314 314
315 Collection where(bool f(int element)) { 315 Iterable where(bool f(int element)) {
316 return IterableMixinWorkaround.where(this, f); 316 return IterableMixinWorkaround.where(this, f);
317 } 317 }
318 318
319 Iterable expand(Iterable f(int element)) { 319 Iterable expand(Iterable f(int element)) {
320 return IterableMixinWorkaround.expand(this, f); 320 return IterableMixinWorkaround.expand(this, f);
321 } 321 }
322 322
323 Iterable take(int n) { 323 Iterable take(int n) {
324 return IterableMixinWorkaround.takeList(this, n); 324 return IterableMixinWorkaround.takeList(this, n);
325 } 325 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if (length < 0) { 571 if (length < 0) {
572 String message = "$length must be greater than 0"; 572 String message = "$length must be greater than 0";
573 throw new ArgumentError(message); 573 throw new ArgumentError(message);
574 } 574 }
575 return _new(length); 575 return _new(length);
576 } 576 }
577 577
578 factory _Int8Array.view(ByteBuffer buffer, 578 factory _Int8Array.view(ByteBuffer buffer,
579 [int offsetInBytes = 0, int length]) { 579 [int offsetInBytes = 0, int length]) {
580 if (length == null) { 580 if (length == null) {
581 length = buffer.lengthInBytes; 581 length = buffer.lengthInBytes - offsetInBytes;
582 } 582 }
583 return new _Int8ArrayView(buffer, offsetInBytes, length); 583 return new _Int8ArrayView(buffer, offsetInBytes, length);
584 } 584 }
585 585
586 586
587 // Method(s) implementing List interface. 587 // Method(s) implementing List interface.
588 588
589 int operator[](int index) { 589 int operator[](int index) {
590 if (index < 0 || index >= length) { 590 if (index < 0 || index >= length) {
591 _throwRangeError(index, length); 591 _throwRangeError(index, length);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 if (length < 0) { 629 if (length < 0) {
630 String message = "$length must be greater than 0"; 630 String message = "$length must be greater than 0";
631 throw new ArgumentError(message); 631 throw new ArgumentError(message);
632 } 632 }
633 return _new(length); 633 return _new(length);
634 } 634 }
635 635
636 factory _Uint8Array.view(ByteBuffer buffer, 636 factory _Uint8Array.view(ByteBuffer buffer,
637 [int offsetInBytes = 0, int length]) { 637 [int offsetInBytes = 0, int length]) {
638 if (length == null) { 638 if (length == null) {
639 length = buffer.lengthInBytes; 639 length = buffer.lengthInBytes - offsetInBytes;
640 } 640 }
641 return new _Uint8ArrayView(buffer, offsetInBytes, length); 641 return new _Uint8ArrayView(buffer, offsetInBytes, length);
642 } 642 }
643 643
644 644
645 // Methods implementing List interface. 645 // Methods implementing List interface.
646 int operator[](int index) { 646 int operator[](int index) {
647 if (index < 0 || index >= length) { 647 if (index < 0 || index >= length) {
648 _throwRangeError(index, length); 648 _throwRangeError(index, length);
649 } 649 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (length < 0) { 685 if (length < 0) {
686 String message = "$length must be greater than 0"; 686 String message = "$length must be greater than 0";
687 throw new ArgumentError(message); 687 throw new ArgumentError(message);
688 } 688 }
689 return _new(length); 689 return _new(length);
690 } 690 }
691 691
692 factory _Uint8ClampedArray.view(ByteBuffer buffer, 692 factory _Uint8ClampedArray.view(ByteBuffer buffer,
693 [int offsetInBytes = 0, int length]) { 693 [int offsetInBytes = 0, int length]) {
694 if (length == null) { 694 if (length == null) {
695 length = buffer.lengthInBytes; 695 length = buffer.lengthInBytes - offsetInBytes;
696 } 696 }
697 return new _Uint8ClampedArrayView(buffer, offsetInBytes, length); 697 return new _Uint8ClampedArrayView(buffer, offsetInBytes, length);
698 } 698 }
699 699
700 700
701 // Methods implementing List interface. 701 // Methods implementing List interface.
702 702
703 int operator[](int index) { 703 int operator[](int index) {
704 if (index < 0 || index >= length) { 704 if (index < 0 || index >= length) {
705 _throwRangeError(index, length); 705 _throwRangeError(index, length);
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 2315
2316 2316
2317 // Internal utility methods. 2317 // Internal utility methods.
2318 2318
2319 Uint8List _createList(int length) { 2319 Uint8List _createList(int length) {
2320 return new Uint8List(length); 2320 return new Uint8List(length);
2321 } 2321 }
2322 } 2322 }
2323 2323
2324 2324
2325 class _Uint8ClampedArrayView extends _TypedListView implements Uint8List { 2325 class _Uint8ClampedArrayView extends _TypedListView implements Uint8ClampedList {
2326 // Constructor. 2326 // Constructor.
2327 _Uint8ClampedArrayView(ByteBuffer buffer, 2327 _Uint8ClampedArrayView(ByteBuffer buffer,
2328 [int _offsetInBytes = 0, int _length]) 2328 [int _offsetInBytes = 0, int _length])
2329 : super(buffer, _offsetInBytes, 2329 : super(buffer, _offsetInBytes,
2330 _defaultIfNull(_length, 2330 _defaultIfNull(_length,
2331 ((buffer.lengthInBytes - _offsetInBytes) ~/ 2331 ((buffer.lengthInBytes - _offsetInBytes) ~/
2332 Uint8List.BYTES_PER_ELEMENT))) { 2332 Uint8List.BYTES_PER_ELEMENT))) {
2333 _rangeCheck(buffer.lengthInBytes, 2333 _rangeCheck(buffer.lengthInBytes,
2334 offsetInBytes, 2334 offsetInBytes,
2335 length * Uint8List.BYTES_PER_ELEMENT); 2335 length * Uint8List.BYTES_PER_ELEMENT);
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
3081 return value; 3081 return value;
3082 } 3082 }
3083 return object; 3083 return object;
3084 } 3084 }
3085 3085
3086 3086
3087 void _throwRangeError(int index, int length) { 3087 void _throwRangeError(int index, int length) {
3088 String message = "$index must be in the range [0..$length)"; 3088 String message = "$index must be in the range [0..$length)";
3089 throw new RangeError(message); 3089 throw new RangeError(message);
3090 } 3090 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/typed_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698