Skip to content

Commit 0a436b7

Browse files
rakudramaCommit Queue
authored and
Commit Queue
committed
Reapply "[typed_data] Deprecate UnmodifiableUint8ListView and friends"
This reverts commit 4918d3e. `@Deprecated` annotations have been commented out. CoreLibraryReviewExempt: reviewed as https://dart-review.googlesource.com/c/sdk/+/321922 TEST=ci Bug: #53785 Change-Id: I3239251c2aba5f188aa947f0ff0208271d6be5cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331741 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]> Reviewed-by: Derek Xu <[email protected]>
1 parent fa7c42a commit 0a436b7

14 files changed

+844
-55
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
## 3.3.0
22

3+
### Libraries
4+
5+
#### `dart:typed_data`
6+
7+
- **BREAKING CHANGE** (https://github.com/dart-lang/sdk/issues/53218) The
8+
unmodifiable view classes for typed data are deprecated. Instead of using the
9+
constructors for these classes to create an unmodifiable view, e.g.
10+
11+
```dart
12+
Uint8List data = ...
13+
final readOnlyView = UnmodifableUint8ListView(data);
14+
```
15+
16+
use the new `asUnmodifiableView()` method:
17+
18+
```dart
19+
Uint8List data = ...
20+
final readOnlyView = data.asUnmodifiableView();
21+
```
22+
23+
The reason for this change is to allow more flexibility in the implementation
24+
of typed data so the native and web platforms can use different strategies
25+
for ensuring typed data has good performance.
26+
27+
The deprecated types will be removed in the next Dart version.
28+
329
### Tools
430

531
#### Dart command line

sdk/lib/_internal/js_dev_runtime/patch/typed_data_patch.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ final class _UnmodifiableByteDataView
264264

265265
_UnmodifiableByteDataView(ByteData data) : _data = data;
266266

267+
ByteData asUnmodifiableView() => this;
268+
267269
int getInt8(int byteOffset) => _data.getInt8(byteOffset);
268270

269271
void setInt8(int byteOffset, int value) => _unsupported();
@@ -372,6 +374,8 @@ final class _UnmodifiableUint8ListView extends UnmodifiableListBase<int>
372374
final Uint8List _list;
373375
_UnmodifiableUint8ListView(Uint8List list) : _list = list;
374376

377+
Uint8List asUnmodifiableView() => this;
378+
375379
Uint8List _createList(int length) => Uint8List(length);
376380
}
377381

@@ -385,6 +389,8 @@ final class _UnmodifiableInt8ListView extends UnmodifiableListBase<int>
385389
final Int8List _list;
386390
_UnmodifiableInt8ListView(Int8List list) : _list = list;
387391

392+
Int8List asUnmodifiableView() => this;
393+
388394
Int8List _createList(int length) => Int8List(length);
389395
}
390396

@@ -398,6 +404,8 @@ final class _UnmodifiableUint8ClampedListView extends UnmodifiableListBase<int>
398404
final Uint8ClampedList _list;
399405
_UnmodifiableUint8ClampedListView(Uint8ClampedList list) : _list = list;
400406

407+
Uint8ClampedList asUnmodifiableView() => this;
408+
401409
Uint8ClampedList _createList(int length) => Uint8ClampedList(length);
402410
}
403411

@@ -411,6 +419,8 @@ final class _UnmodifiableUint16ListView extends UnmodifiableListBase<int>
411419
final Uint16List _list;
412420
_UnmodifiableUint16ListView(Uint16List list) : _list = list;
413421

422+
Uint16List asUnmodifiableView() => this;
423+
414424
Uint16List _createList(int length) => Uint16List(length);
415425
}
416426

@@ -424,6 +434,8 @@ final class _UnmodifiableInt16ListView extends UnmodifiableListBase<int>
424434
final Int16List _list;
425435
_UnmodifiableInt16ListView(Int16List list) : _list = list;
426436

437+
Int16List asUnmodifiableView() => this;
438+
427439
Int16List _createList(int length) => Int16List(length);
428440
}
429441

@@ -437,6 +449,8 @@ final class _UnmodifiableUint32ListView extends UnmodifiableListBase<int>
437449
final Uint32List _list;
438450
_UnmodifiableUint32ListView(Uint32List list) : _list = list;
439451

452+
Uint32List asUnmodifiableView() => this;
453+
440454
Uint32List _createList(int length) => Uint32List(length);
441455
}
442456

@@ -450,6 +464,8 @@ final class _UnmodifiableInt32ListView extends UnmodifiableListBase<int>
450464
final Int32List _list;
451465
_UnmodifiableInt32ListView(Int32List list) : _list = list;
452466

467+
Int32List asUnmodifiableView() => this;
468+
453469
Int32List _createList(int length) => Int32List(length);
454470
}
455471

@@ -463,6 +479,8 @@ final class _UnmodifiableUint64ListView extends UnmodifiableListBase<int>
463479
final Uint64List _list;
464480
_UnmodifiableUint64ListView(Uint64List list) : _list = list;
465481

482+
Uint64List asUnmodifiableView() => this;
483+
466484
Uint64List _createList(int length) => Uint64List(length);
467485
}
468486

@@ -476,6 +494,8 @@ final class _UnmodifiableInt64ListView extends UnmodifiableListBase<int>
476494
final Int64List _list;
477495
_UnmodifiableInt64ListView(Int64List list) : _list = list;
478496

497+
Int64List asUnmodifiableView() => this;
498+
479499
Int64List _createList(int length) => Int64List(length);
480500
}
481501

@@ -489,6 +509,8 @@ final class _UnmodifiableInt32x4ListView extends UnmodifiableListBase<Int32x4>
489509
final Int32x4List _list;
490510
_UnmodifiableInt32x4ListView(Int32x4List list) : _list = list;
491511

512+
Int32x4List asUnmodifiableView() => this;
513+
492514
Int32x4List _createList(int length) => Int32x4List(length);
493515
}
494516

@@ -503,6 +525,8 @@ final class _UnmodifiableFloat32x4ListView
503525
final Float32x4List _list;
504526
_UnmodifiableFloat32x4ListView(Float32x4List list) : _list = list;
505527

528+
Float32x4List asUnmodifiableView() => this;
529+
506530
Float32x4List _createList(int length) => Float32x4List(length);
507531
}
508532

@@ -517,6 +541,8 @@ final class _UnmodifiableFloat64x2ListView
517541
final Float64x2List _list;
518542
_UnmodifiableFloat64x2ListView(Float64x2List list) : _list = list;
519543

544+
Float64x2List asUnmodifiableView() => this;
545+
520546
Float64x2List _createList(int length) => Float64x2List(length);
521547
}
522548

@@ -530,6 +556,8 @@ final class _UnmodifiableFloat32ListView extends UnmodifiableListBase<double>
530556
final Float32List _list;
531557
_UnmodifiableFloat32ListView(Float32List list) : _list = list;
532558

559+
Float32List asUnmodifiableView() => this;
560+
533561
Float32List _createList(int length) => Float32List(length);
534562
}
535563

@@ -543,6 +571,8 @@ final class _UnmodifiableFloat64ListView extends UnmodifiableListBase<double>
543571
final Float64List _list;
544572
_UnmodifiableFloat64ListView(Float64List list) : _list = list;
545573

574+
Float64List asUnmodifiableView() => this;
575+
546576
Float64List _createList(int length) => Float64List(length);
547577
}
548578

sdk/lib/_internal/js_dev_runtime/private/native_typed_data.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ final class NativeFloat32x4List extends Object
162162
_storage[(index * 4) + 3] = value.w;
163163
}
164164

165+
Float32x4List asUnmodifiableView() => UnmodifiableFloat32x4ListView(this);
166+
165167
Float32x4List sublist(int start, [int? end]) {
166168
var stop = _checkValidRange(start, end, this.length);
167169
return NativeFloat32x4List._externalStorage(
@@ -234,6 +236,8 @@ final class NativeInt32x4List extends Object
234236
_storage[(index * 4) + 3] = value.w;
235237
}
236238

239+
Int32x4List asUnmodifiableView() => UnmodifiableInt32x4ListView(this);
240+
237241
Int32x4List sublist(int start, [int? end]) {
238242
var stop = _checkValidRange(start, end, this.length);
239243
return NativeInt32x4List._externalStorage(
@@ -300,6 +304,8 @@ final class NativeFloat64x2List extends Object
300304
_storage[(index * 2) + 1] = value.y;
301305
}
302306

307+
Float64x2List asUnmodifiableView() => UnmodifiableFloat64x2ListView(this);
308+
303309
Float64x2List sublist(int start, [int? end]) {
304310
var stop = _checkValidRange(start, end, this.length);
305311
return NativeFloat64x2List._externalStorage(
@@ -407,6 +413,8 @@ final class NativeByteData extends NativeTypedData implements ByteData {
407413

408414
int get elementSizeInBytes => 1;
409415

416+
ByteData asUnmodifiableView() => UnmodifiableByteDataView(this);
417+
410418
/// Returns the floating point number represented by the four bytes at
411419
/// the specified [byteOffset] in this object, in IEEE 754
412420
/// single-precision binary floating-point format (binary32).
@@ -757,6 +765,8 @@ final class NativeFloat32List extends NativeTypedArrayOfDouble
757765

758766
Type get runtimeType => Float32List;
759767

768+
Float32List asUnmodifiableView() => UnmodifiableFloat32ListView(this);
769+
760770
Float32List sublist(int start, [int? end]) {
761771
var stop = _checkValidRange(start, end, this.length);
762772
var source =
@@ -789,6 +799,8 @@ final class NativeFloat64List extends NativeTypedArrayOfDouble
789799

790800
Type get runtimeType => Float64List;
791801

802+
Float64List asUnmodifiableView() => UnmodifiableFloat64ListView(this);
803+
792804
Float64List sublist(int start, [int? end]) {
793805
var stop = _checkValidRange(start, end, this.length);
794806
var source = JS('NativeFloat64List', '#.subarray(#, #)', this, start, stop);
@@ -824,6 +836,8 @@ final class NativeInt16List extends NativeTypedArrayOfInt implements Int16List {
824836
return JS<int>('!', '#[#]', this, index);
825837
}
826838

839+
Int16List asUnmodifiableView() => UnmodifiableInt16ListView(this);
840+
827841
Int16List sublist(int start, [int? end]) {
828842
var stop = _checkValidRange(start, end, this.length);
829843
var source = JS('NativeInt16List', '#.subarray(#, #)', this, start, stop);
@@ -859,6 +873,8 @@ final class NativeInt32List extends NativeTypedArrayOfInt implements Int32List {
859873
return JS<int>('!', '#[#]', this, index);
860874
}
861875

876+
Int32List asUnmodifiableView() => UnmodifiableInt32ListView(this);
877+
862878
Int32List sublist(int start, [int? end]) {
863879
var stop = _checkValidRange(start, end, this.length);
864880
var source =
@@ -895,6 +911,8 @@ final class NativeInt8List extends NativeTypedArrayOfInt implements Int8List {
895911
return JS<int>('!', '#[#]', this, index);
896912
}
897913

914+
Int8List asUnmodifiableView() => UnmodifiableInt8ListView(this);
915+
898916
Int8List sublist(int start, [int? end]) {
899917
var stop = _checkValidRange(start, end, this.length);
900918
var source = JS<NativeInt8List>('!', '#.subarray(#, #)', this, start, stop);
@@ -934,6 +952,8 @@ final class NativeUint16List extends NativeTypedArrayOfInt
934952
return JS<int>('!', '#[#]', this, index);
935953
}
936954

955+
Uint16List asUnmodifiableView() => UnmodifiableUint16ListView(this);
956+
937957
Uint16List sublist(int start, [int? end]) {
938958
var stop = _checkValidRange(start, end, this.length);
939959
var source =
@@ -971,6 +991,8 @@ final class NativeUint32List extends NativeTypedArrayOfInt
971991
return JS<int>('!', '#[#]', this, index);
972992
}
973993

994+
Uint32List asUnmodifiableView() => UnmodifiableUint32ListView(this);
995+
974996
Uint32List sublist(int start, [int? end]) {
975997
var stop = _checkValidRange(start, end, this.length);
976998
var source =
@@ -1010,6 +1032,9 @@ final class NativeUint8ClampedList extends NativeTypedArrayOfInt
10101032
return JS<int>('!', '#[#]', this, index);
10111033
}
10121034

1035+
Uint8ClampedList asUnmodifiableView() =>
1036+
UnmodifiableUint8ClampedListView(this);
1037+
10131038
Uint8ClampedList sublist(int start, [int? end]) {
10141039
var stop = _checkValidRange(start, end, this.length);
10151040
var source =
@@ -1060,6 +1085,8 @@ final class NativeUint8List extends NativeTypedArrayOfInt implements Uint8List {
10601085
return JS<int>('!', '#[#]', this, index);
10611086
}
10621087

1088+
Uint8List asUnmodifiableView() => UnmodifiableUint8ListView(this);
1089+
10631090
Uint8List sublist(int start, [int? end]) {
10641091
var stop = _checkValidRange(start, end, this.length);
10651092
var source =

0 commit comments

Comments
 (0)