Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fc3af73

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Update typed-data constructor documentation.
Make it explicit that the allocating constructors allocate precisly the needed amount of bytes. Fixes #40261 Bug: http://dartbug.com/40261 Change-Id: I059a9e3e387fee116e2221a0761557aedc948aee Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132844 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent da1e42a commit fc3af73

File tree

2 files changed

+185
-10
lines changed

2 files changed

+185
-10
lines changed

sdk/lib/typed_data/typed_data.dart

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,12 @@ class Endian {
445445
* Finally, `ByteData` may be used to intentionally reinterpret the bytes
446446
* representing one arithmetic type as another.
447447
* For example this code fragment determine what 32-bit signed integer
448-
* is represented by the bytes of a 32-bit floating point number:
448+
* is represented by the bytes of a 32-bit floating point number
449+
* (both stored as big endian):
449450
*
450-
* var buffer = new Uint8List(8).buffer;
451-
* var bdata = new ByteData.view(buffer);
451+
* var bdata = new ByteData(8);
452452
* bdata.setFloat32(0, 3.04);
453-
* int huh = bdata.getInt32(0);
453+
* int huh = bdata.getInt32(0); // 0x40428f5c
454454
*/
455455
abstract class ByteData implements TypedData {
456456
/**
@@ -787,6 +787,8 @@ abstract class Int8List implements List<int>, _TypedIntList {
787787
/**
788788
* Creates an [Int8List] of the specified length (in elements), all of
789789
* whose elements are initially zero.
790+
*
791+
* The list is backed by a [ByteBuffer] containing precisely [length] bytes.
790792
*/
791793
external factory Int8List(int length);
792794

@@ -796,6 +798,9 @@ abstract class Int8List implements List<int>, _TypedIntList {
796798
*
797799
* Values are truncated to fit in the list when they are copied,
798800
* the same way storing values truncates them.
801+
*
802+
* The list is backed by a [ByteBuffer] containing precisely `elements.length`
803+
* bytes.
799804
*/
800805
external factory Int8List.fromList(List<int> elements);
801806

@@ -904,6 +909,8 @@ abstract class Uint8List implements List<int>, _TypedIntList {
904909
/**
905910
* Creates a [Uint8List] of the specified length (in elements), all of
906911
* whose elements are initially zero.
912+
*
913+
* The list is backed by a [ByteBuffer] containing precisely [length] bytes.
907914
*/
908915
external factory Uint8List(int length);
909916

@@ -913,6 +920,9 @@ abstract class Uint8List implements List<int>, _TypedIntList {
913920
*
914921
* Values are truncated to fit in the list when they are copied,
915922
* the same way storing values truncates them.
923+
*
924+
* The list is backed by a [ByteBuffer] containing precisely `elements.length`
925+
* bytes.
916926
*/
917927
external factory Uint8List.fromList(List<int> elements);
918928

@@ -1030,6 +1040,8 @@ abstract class Uint8ClampedList implements List<int>, _TypedIntList {
10301040
/**
10311041
* Creates a [Uint8ClampedList] of the specified length (in elements), all of
10321042
* whose elements are initially zero.
1043+
*
1044+
* The list is backed by a [ByteBuffer] containing precisely [length] bytes.
10331045
*/
10341046
external factory Uint8ClampedList(int length);
10351047

@@ -1039,6 +1051,9 @@ abstract class Uint8ClampedList implements List<int>, _TypedIntList {
10391051
*
10401052
* Values are clamped to fit in the list when they are copied,
10411053
* the same way storing values clamps them.
1054+
*
1055+
* The list is backed by a [ByteBuffer] containing precisely `elements.length`
1056+
* bytes.
10421057
*/
10431058
external factory Uint8ClampedList.fromList(List<int> elements);
10441059

@@ -1150,6 +1165,9 @@ abstract class Int16List implements List<int>, _TypedIntList {
11501165
/**
11511166
* Creates an [Int16List] of the specified length (in elements), all of
11521167
* whose elements are initially zero.
1168+
*
1169+
* The list is backed by a [ByteBuffer] containing precisely
1170+
* [length] times 2 bytes.
11531171
*/
11541172
external factory Int16List(int length);
11551173

@@ -1159,6 +1177,9 @@ abstract class Int16List implements List<int>, _TypedIntList {
11591177
*
11601178
* Values are truncated to fit in the list when they are copied,
11611179
* the same way storing values truncates them.
1180+
*
1181+
* The list is backed by a [ByteBuffer] containing precisely
1182+
* `elements.length` times 2 bytes.
11621183
*/
11631184
external factory Int16List.fromList(List<int> elements);
11641185

@@ -1279,6 +1300,9 @@ abstract class Uint16List implements List<int>, _TypedIntList {
12791300
/**
12801301
* Creates a [Uint16List] of the specified length (in elements), all
12811302
* of whose elements are initially zero.
1303+
*
1304+
* The list is backed by a [ByteBuffer] containing precisely
1305+
* [length] times 2 bytes.
12821306
*/
12831307
external factory Uint16List(int length);
12841308

@@ -1288,6 +1312,9 @@ abstract class Uint16List implements List<int>, _TypedIntList {
12881312
*
12891313
* Values are truncated to fit in the list when they are copied,
12901314
* the same way storing values truncates them.
1315+
*
1316+
* The list is backed by a [ByteBuffer] containing precisely
1317+
* `elements.length` times 2 bytes.
12911318
*/
12921319
external factory Uint16List.fromList(List<int> elements);
12931320

@@ -1409,6 +1436,9 @@ abstract class Int32List implements List<int>, _TypedIntList {
14091436
/**
14101437
* Creates an [Int32List] of the specified length (in elements), all of
14111438
* whose elements are initially zero.
1439+
*
1440+
* The list is backed by a [ByteBuffer] containing precisely
1441+
* [length] times 4 bytes.
14121442
*/
14131443
external factory Int32List(int length);
14141444

@@ -1418,6 +1448,9 @@ abstract class Int32List implements List<int>, _TypedIntList {
14181448
*
14191449
* Values are truncated to fit in the list when they are copied,
14201450
* the same way storing values truncates them.
1451+
*
1452+
* The list is backed by a [ByteBuffer] containing precisely
1453+
* `elements.length` times 4 bytes.
14211454
*/
14221455
external factory Int32List.fromList(List<int> elements);
14231456

@@ -1538,6 +1571,9 @@ abstract class Uint32List implements List<int>, _TypedIntList {
15381571
/**
15391572
* Creates a [Uint32List] of the specified length (in elements), all
15401573
* of whose elements are initially zero.
1574+
*
1575+
* The list is backed by a [ByteBuffer] containing precisely
1576+
* [length] times 4 bytes.
15411577
*/
15421578
external factory Uint32List(int length);
15431579

@@ -1547,6 +1583,9 @@ abstract class Uint32List implements List<int>, _TypedIntList {
15471583
*
15481584
* Values are truncated to fit in the list when they are copied,
15491585
* the same way storing values truncates them.
1586+
*
1587+
* The list is backed by a [ByteBuffer] containing precisely
1588+
* `elements.length` times 4 bytes.
15501589
*/
15511590
external factory Uint32List.fromList(List<int> elements);
15521591

@@ -1668,6 +1707,9 @@ abstract class Int64List implements List<int>, _TypedIntList {
16681707
/**
16691708
* Creates an [Int64List] of the specified length (in elements), all of
16701709
* whose elements are initially zero.
1710+
*
1711+
* The list is backed by a [ByteBuffer] containing precisely
1712+
* [length] times 8 bytes.
16711713
*/
16721714
external factory Int64List(int length);
16731715

@@ -1677,6 +1719,9 @@ abstract class Int64List implements List<int>, _TypedIntList {
16771719
*
16781720
* Values are truncated to fit in the list when they are copied,
16791721
* the same way storing values truncates them.
1722+
*
1723+
* The list is backed by a [ByteBuffer] containing precisely
1724+
* `elements.length` times 8 bytes.
16801725
*/
16811726
external factory Int64List.fromList(List<int> elements);
16821727

@@ -1797,6 +1842,9 @@ abstract class Uint64List implements List<int>, _TypedIntList {
17971842
/**
17981843
* Creates a [Uint64List] of the specified length (in elements), all
17991844
* of whose elements are initially zero.
1845+
*
1846+
* The list is backed by a [ByteBuffer] containing precisely
1847+
* [length] times 8 bytes.
18001848
*/
18011849
external factory Uint64List(int length);
18021850

@@ -1806,6 +1854,9 @@ abstract class Uint64List implements List<int>, _TypedIntList {
18061854
*
18071855
* Values are truncated to fit in the list when they are copied,
18081856
* the same way storing values truncates them.
1857+
*
1858+
* The list is backed by a [ByteBuffer] containing precisely
1859+
* `elements.length` times 8 bytes.
18091860
*/
18101861
external factory Uint64List.fromList(List<int> elements);
18111862

@@ -1928,6 +1979,9 @@ abstract class Float32List implements List<double>, _TypedFloatList {
19281979
/**
19291980
* Creates a [Float32List] of the specified length (in elements), all of
19301981
* whose elements are initially zero.
1982+
*
1983+
* The list is backed by a [ByteBuffer] containing precisely
1984+
* [length] times 4 bytes.
19311985
*/
19321986
external factory Float32List(int length);
19331987

@@ -1937,6 +1991,9 @@ abstract class Float32List implements List<double>, _TypedFloatList {
19371991
*
19381992
* Values are truncated to fit in the list when they are copied,
19391993
* the same way storing values truncates them.
1994+
*
1995+
* The list is backed by a [ByteBuffer] containing precisely
1996+
* `elements.length` times 4 bytes.
19401997
*/
19411998
external factory Float32List.fromList(List<double> elements);
19421999

@@ -2054,12 +2111,18 @@ abstract class Float64List implements List<double>, _TypedFloatList {
20542111
/**
20552112
* Creates a [Float64List] of the specified length (in elements), all of
20562113
* whose elements are initially zero.
2114+
*
2115+
* The list is backed by a [ByteBuffer] containing precisely
2116+
* [length] times 8 bytes.
20572117
*/
20582118
external factory Float64List(int length);
20592119

20602120
/**
20612121
* Creates a [Float64List] with the same length as the [elements] list
20622122
* and copies over the elements.
2123+
*
2124+
* The list is backed by a [ByteBuffer] containing precisely
2125+
* `elements.length` times 8 bytes.
20632126
*/
20642127
external factory Float64List.fromList(List<double> elements);
20652128

@@ -2176,12 +2239,18 @@ abstract class Float32x4List implements List<Float32x4>, TypedData {
21762239
/**
21772240
* Creates a [Float32x4List] of the specified length (in elements),
21782241
* all of whose elements are initially zero.
2242+
*
2243+
* The list is backed by a [ByteBuffer] containing precisely
2244+
* [length] times 16 bytes.
21792245
*/
21802246
external factory Float32x4List(int length);
21812247

21822248
/**
21832249
* Creates a [Float32x4List] with the same length as the [elements] list
21842250
* and copies over the elements.
2251+
*
2252+
* The list is backed by a [ByteBuffer] containing precisely
2253+
* `elements.length` times 16 bytes.
21852254
*/
21862255
external factory Float32x4List.fromList(List<Float32x4> elements);
21872256

@@ -2306,12 +2375,18 @@ abstract class Int32x4List implements List<Int32x4>, TypedData {
23062375
/**
23072376
* Creates a [Int32x4List] of the specified length (in elements),
23082377
* all of whose elements are initially zero.
2378+
*
2379+
* The list is backed by a [ByteBuffer] containing precisely
2380+
* [length] times 16 bytes.
23092381
*/
23102382
external factory Int32x4List(int length);
23112383

23122384
/**
23132385
* Creates a [Int32x4List] with the same length as the [elements] list
23142386
* and copies over the elements.
2387+
*
2388+
* The list is backed by a [ByteBuffer] containing precisely
2389+
* `elements.length` times 16 bytes.
23152390
*/
23162391
external factory Int32x4List.fromList(List<Int32x4> elements);
23172392

@@ -2436,12 +2511,18 @@ abstract class Float64x2List implements List<Float64x2>, TypedData {
24362511
/**
24372512
* Creates a [Float64x2List] of the specified length (in elements),
24382513
* all of whose elements have all lanes set to zero.
2514+
*
2515+
* The list is backed by a [ByteBuffer] containing precisely
2516+
* [length] times 16 bytes.
24392517
*/
24402518
external factory Float64x2List(int length);
24412519

24422520
/**
24432521
* Creates a [Float64x2List] with the same length as the [elements] list
24442522
* and copies over the elements.
2523+
*
2524+
* The list is backed by a [ByteBuffer] containing precisely
2525+
* `elements.length` times 16 bytes.
24452526
*/
24462527
external factory Float64x2List.fromList(List<Float64x2> elements);
24472528

0 commit comments

Comments
 (0)