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

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

Issue 1999793002: Make Iterable.toList more efficient if the length is known. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Avoid iterator for empty list Created 4 years, 7 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
« no previous file with comments | « runtime/lib/array_patch.dart ('k') | sdk/lib/collection/queue.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 library dart.typed_data; 5 library dart.typed_data;
6 6
7 import "dart:_internal"; 7 import "dart:_internal";
8 import "dart:collection" show ListBase; 8 import "dart:collection" show ListBase;
9 import 'dart:math' show Random; 9 import 'dart:math' show Random;
10 10
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 Iterable<int> get reversed => new ReversedListIterable<int>(this); 728 Iterable<int> get reversed => new ReversedListIterable<int>(this);
729 729
730 Map<int, int> asMap() => new ListMapView<int>(this); 730 Map<int, int> asMap() => new ListMapView<int>(this);
731 731
732 Iterable<int> getRange(int start, [int end]) { 732 Iterable<int> getRange(int start, [int end]) {
733 RangeError.checkValidRange(start, end, this.length); 733 RangeError.checkValidRange(start, end, this.length);
734 return new SubListIterable<int>(this, start, end); 734 return new SubListIterable<int>(this, start, end);
735 } 735 }
736 736
737 Iterator<int> get iterator => new _TypedListIterator<int>(this); 737 Iterator<int> get iterator => new _TypedListIterator<int>(this);
738
739 List<int> toList({bool growable: true}) {
740 return new List<int>.from(this, growable: growable);
741 }
742
743 Set<int> toSet() {
744 return new Set<int>.from(this);
745 }
738 } 746 }
739 747
740 748
741 class _DoubleListMixin { 749 class _DoubleListMixin {
742 Iterable<double> where(bool f(int element)) => 750 Iterable<double> where(bool f(int element)) =>
743 new WhereIterable<double>(this, f); 751 new WhereIterable<double>(this, f);
744 752
745 Iterable<double> take(int n) => new SubListIterable<double>(this, 0, n); 753 Iterable<double> take(int n) => new SubListIterable<double>(this, 0, n);
746 754
747 Iterable<double> takeWhile(bool test(int element)) => 755 Iterable<double> takeWhile(bool test(int element)) =>
748 new TakeWhileIterable<double>(this, test); 756 new TakeWhileIterable<double>(this, test);
749 757
750 Iterable<double> skip(int n) => new SubListIterable<double>(this, n, null); 758 Iterable<double> skip(int n) => new SubListIterable<double>(this, n, null);
751 759
752 Iterable<double> skipWhile(bool test(element)) => 760 Iterable<double> skipWhile(bool test(element)) =>
753 new SkipWhileIterable<double>(this, test); 761 new SkipWhileIterable<double>(this, test);
754 762
755 Iterable<double> get reversed => new ReversedListIterable<double>(this); 763 Iterable<double> get reversed => new ReversedListIterable<double>(this);
756 764
757 Map<int, double> asMap() => new ListMapView<double>(this); 765 Map<int, double> asMap() => new ListMapView<double>(this);
758 766
759 Iterable<double> getRange(int start, [int end]) { 767 Iterable<double> getRange(int start, [int end]) {
760 RangeError.checkValidRange(start, end, this.length); 768 RangeError.checkValidRange(start, end, this.length);
761 return new SubListIterable<double>(this, start, end); 769 return new SubListIterable<double>(this, start, end);
762 } 770 }
763 771
764 Iterator<double> get iterator => new _TypedListIterator<double>(this); 772 Iterator<double> get iterator => new _TypedListIterator<double>(this);
773
774 List<double> toList({bool growable: true}) {
775 return new List<double>.from(this, growable: growable);
776 }
777
778 Set<double> toSet() {
779 return new Set<double>.from(this);
780 }
765 } 781 }
766 782
767 783
768 class _Float32x4ListMixin { 784 class _Float32x4ListMixin {
769 Iterable<Float32x4> where(bool f(int element)) => 785 Iterable<Float32x4> where(bool f(int element)) =>
770 new WhereIterable<Float32x4>(this, f); 786 new WhereIterable<Float32x4>(this, f);
771 787
772 Iterable<Float32x4> take(int n) => new SubListIterable<Float32x4>(this, 0, n); 788 Iterable<Float32x4> take(int n) => new SubListIterable<Float32x4>(this, 0, n);
773 789
774 Iterable<Float32x4> takeWhile(bool test(int element)) => 790 Iterable<Float32x4> takeWhile(bool test(int element)) =>
775 new TakeWhileIterable<Float32x4>(this, test); 791 new TakeWhileIterable<Float32x4>(this, test);
776 792
777 Iterable<Float32x4> skip(int n) => 793 Iterable<Float32x4> skip(int n) =>
778 new SubListIterable<Float32x4>(this, n, null); 794 new SubListIterable<Float32x4>(this, n, null);
779 795
780 Iterable<Float32x4> skipWhile(bool test(element)) => 796 Iterable<Float32x4> skipWhile(bool test(element)) =>
781 new SkipWhileIterable<Float32x4>(this, test); 797 new SkipWhileIterable<Float32x4>(this, test);
782 798
783 Iterable<Float32x4> get reversed => new ReversedListIterable<Float32x4>(this); 799 Iterable<Float32x4> get reversed => new ReversedListIterable<Float32x4>(this);
784 800
785 Map<int, Float32x4> asMap() => new ListMapView<Float32x4>(this); 801 Map<int, Float32x4> asMap() => new ListMapView<Float32x4>(this);
786 802
787 Iterable<Float32x4> getRange(int start, [int end]) { 803 Iterable<Float32x4> getRange(int start, [int end]) {
788 RangeError.checkValidRange(start, end, this.length); 804 RangeError.checkValidRange(start, end, this.length);
789 return new SubListIterable<Float32x4>(this, start, end); 805 return new SubListIterable<Float32x4>(this, start, end);
790 } 806 }
791 807
792 Iterator<Float32x4> get iterator => new _TypedListIterator<Float32x4>(this); 808 Iterator<Float32x4> get iterator => new _TypedListIterator<Float32x4>(this);
809
810 List<Float32x4> toList({bool growable: true}) {
811 return new List<Float32x4>.from(this, growable: growable);
812 }
813
814 Set<Float32x4> toSet() {
815 return new Set<Float32x4>.from(this);
816 }
793 } 817 }
794 818
795 819
796 class _Int32x4ListMixin { 820 class _Int32x4ListMixin {
797 Iterable<Int32x4> where(bool f(int element)) => 821 Iterable<Int32x4> where(bool f(int element)) =>
798 new WhereIterable<Int32x4>(this, f); 822 new WhereIterable<Int32x4>(this, f);
799 823
800 Iterable<Int32x4> take(int n) => new SubListIterable<Int32x4>(this, 0, n); 824 Iterable<Int32x4> take(int n) => new SubListIterable<Int32x4>(this, 0, n);
801 825
802 Iterable<Int32x4> takeWhile(bool test(int element)) => 826 Iterable<Int32x4> takeWhile(bool test(int element)) =>
803 new TakeWhileIterable<Int32x4>(this, test); 827 new TakeWhileIterable<Int32x4>(this, test);
804 828
805 Iterable<Int32x4> skip(int n) => new SubListIterable<Int32x4>(this, n, null); 829 Iterable<Int32x4> skip(int n) => new SubListIterable<Int32x4>(this, n, null);
806 830
807 Iterable<Int32x4> skipWhile(bool test(element)) => 831 Iterable<Int32x4> skipWhile(bool test(element)) =>
808 new SkipWhileIterable<Int32x4>(this, test); 832 new SkipWhileIterable<Int32x4>(this, test);
809 833
810 Iterable<Int32x4> get reversed => new ReversedListIterable<Int32x4>(this); 834 Iterable<Int32x4> get reversed => new ReversedListIterable<Int32x4>(this);
811 835
812 Map<int, Int32x4> asMap() => new ListMapView<Int32x4>(this); 836 Map<int, Int32x4> asMap() => new ListMapView<Int32x4>(this);
813 837
814 Iterable<Int32x4> getRange(int start, [int end]) { 838 Iterable<Int32x4> getRange(int start, [int end]) {
815 RangeError.checkValidRange(start, end, this.length); 839 RangeError.checkValidRange(start, end, this.length);
816 return new SubListIterable<Int32x4>(this, start, end); 840 return new SubListIterable<Int32x4>(this, start, end);
817 } 841 }
818 842
819 Iterator<Int32x4> get iterator => new _TypedListIterator<Int32x4>(this); 843 Iterator<Int32x4> get iterator => new _TypedListIterator<Int32x4>(this);
844
845 List<Int32x4> toList({bool growable: true}) {
846 return new List<Int32x4>.from(this, growable: growable);
847 }
848
849 Set<Int32x4> toSet() {
850 return new Set<Int32x4>.from(this);
851 }
820 } 852 }
821 853
822 854
823 class _Float64x2ListMixin { 855 class _Float64x2ListMixin {
824 Iterable<Float64x2> where(bool f(int element)) => 856 Iterable<Float64x2> where(bool f(int element)) =>
825 new WhereIterable<Float64x2>(this, f); 857 new WhereIterable<Float64x2>(this, f);
826 858
827 Iterable<Float64x2> take(int n) => new SubListIterable<Float64x2>(this, 0, n); 859 Iterable<Float64x2> take(int n) => new SubListIterable<Float64x2>(this, 0, n);
828 860
829 Iterable<Float64x2> takeWhile(bool test(int element)) => 861 Iterable<Float64x2> takeWhile(bool test(int element)) =>
830 new TakeWhileIterable<Float64x2>(this, test); 862 new TakeWhileIterable<Float64x2>(this, test);
831 863
832 Iterable<Float64x2> skip(int n) => 864 Iterable<Float64x2> skip(int n) =>
833 new SubListIterable<Float64x2>(this, n, null); 865 new SubListIterable<Float64x2>(this, n, null);
834 866
835 Iterable<Float64x2> skipWhile(bool test(element)) => 867 Iterable<Float64x2> skipWhile(bool test(element)) =>
836 new SkipWhileIterable<Float64x2>(this, test); 868 new SkipWhileIterable<Float64x2>(this, test);
837 869
838 Iterable<Float64x2> get reversed => new ReversedListIterable<Float64x2>(this); 870 Iterable<Float64x2> get reversed => new ReversedListIterable<Float64x2>(this);
839 871
840 Map<int, Float64x2> asMap() => new ListMapView<Float64x2>(this); 872 Map<int, Float64x2> asMap() => new ListMapView<Float64x2>(this);
841 873
842 Iterable<Float64x2> getRange(int start, [int end]) { 874 Iterable<Float64x2> getRange(int start, [int end]) {
843 RangeError.checkValidRange(start, end, this.length); 875 RangeError.checkValidRange(start, end, this.length);
844 return new SubListIterable<Float64x2>(this, start, end); 876 return new SubListIterable<Float64x2>(this, start, end);
845 } 877 }
846 878
847 Iterator<Float64x2> get iterator => new _TypedListIterator<Float64x2>(this); 879 Iterator<Float64x2> get iterator => new _TypedListIterator<Float64x2>(this);
880
881 List<Float64x2> toList({bool growable: true}) {
882 return new List<Float64x2>.from(this, growable: growable);
883 }
884
885 Set<Float64x2> toSet() {
886 return new Set<Float64x2>.from(this);
887 }
848 } 888 }
849 889
850 890
851 class ByteBuffer { 891 class ByteBuffer {
852 final _TypedList _data; 892 final _TypedList _data;
853 893
854 ByteBuffer(this._data); 894 ByteBuffer(this._data);
855 895
856 factory ByteBuffer._New(data) => new ByteBuffer(data); 896 factory ByteBuffer._New(data) => new ByteBuffer(data);
857 897
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 _setUint8(index, _toUint8(value)); 1179 _setUint8(index, _toUint8(value));
1140 } 1180 }
1141 1181
1142 static const int BYTES_PER_ELEMENT = 1; 1182 static const int BYTES_PER_ELEMENT = 1;
1143 1183
1144 // Methods implementing TypedData interface. 1184 // Methods implementing TypedData interface.
1145 int get elementSizeInBytes { 1185 int get elementSizeInBytes {
1146 return Uint8List.BYTES_PER_ELEMENT; 1186 return Uint8List.BYTES_PER_ELEMENT;
1147 } 1187 }
1148 1188
1149
1150 // Internal utility methods. 1189 // Internal utility methods.
1151 1190
1152 Uint8List _createList(int length) { 1191 Uint8List _createList(int length) {
1153 return new Uint8List(length); 1192 return new Uint8List(length);
1154 } 1193 }
1155 } 1194 }
1156 1195
1157 1196
1158 class Uint8ClampedList extends _TypedList with _IntListMixin implements List<int >, TypedData { 1197 class Uint8ClampedList extends _TypedList with _IntListMixin implements List<int >, TypedData {
1159 // Factory constructors. 1198 // Factory constructors.
(...skipping 3105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4265 } 4304 }
4266 } 4305 }
4267 4306
4268 4307
4269 int _defaultIfNull(object, value) { 4308 int _defaultIfNull(object, value) {
4270 if (object == null) { 4309 if (object == null) {
4271 return value; 4310 return value;
4272 } 4311 }
4273 return object; 4312 return object;
4274 } 4313 }
OLDNEW
« no previous file with comments | « runtime/lib/array_patch.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698