-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BytesBuilder.takeBytes should explicitly provide a Uint8List #27818
Comments
This is extremely dangerous. None of these functions promise a |
It is unclear from your reply whether you mean the proposed change is dangerous, or that the status quo is dangerous, and should be changed so the proposed change is safe. Could you clarify, and suggest a resolution? |
We agree that our current code is dangerous, but we don't really have a choice. This is performance-critical code. That's why we'd like the APIs changed to be explicitly always returning raw buffers. It should be a backwards-compatible change. |
Breaking change request: #36900 |
These methods all were returning Uint8List, yet they were only declared to return List<int>. This forced callers to either defensively wrap the return values in Uint8List, or to assume the contravariant return value: * Utf8Codec.encode() * BytesBuilder.takeBytes() * BytesBuilder.toBytes() * File.readAsBytes() * File.readAsBytesSync() * RandomAccessFile.read() * RandomAccessFile.readSync() * Uint8List.sublist() Since it's related, this change also updates the following sublist() methods to declare that they return the a sublist of the same type as the source list: * Int8List * Uint8ClampedList * Int16List * Uint16List * Int32List * Uint32List * Int64List * Uint64List * Float32List * Float64List * Float32x4List * Int32x4List * Float64x2List Bug: #36900 Bug: #31547 Bug: #27818 Bug: #35521 Change-Id: Ic3bc1db0d64de36fb68b1d8d98037eed1464f978 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101742 Commit-Queue: Todd Volkert <tvolkert@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
This is implemented now. |
...so that it can be statically proved that you can obtain a ByteBuffer from the result. Flutter is going to be relying on this all over the place. For example, we're going to rely on File.readAsBytes providing a Uint8List. We already rely on the UTF8 decoder actually returning a Uint8List.
The text was updated successfully, but these errors were encountered: