Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[breaking change] Make utf8.encode() / Utf8Codec.encode() return more precise Uint8List return type #52801

Closed
@mkustermann

Description

@mkustermann

Change Intent

Make Utf8Codec.encode() return a Uint8List instead of a List<int>.

Justification

This change will to allow compilers to better optimize code which is accessing the bytes. It also allows being explicit about the guarantees we make: We already guarantee to return a Uint8List but it's not visible in the return type. Some users then do explicit downcasts via utf8.encode(...) as Uint8List, others pass around List<int> which can result in inefficient code.

Impact

The impact will be more precision in static types and smaller code size / higher performance is some cases. It may break existing code if such code is relying on type inference to infer List<int> and would fail if it would now infer Uint8List.

Mitigation

Explicitly pass List<int> as type arguments in places where the automatically inferred Uint8List type is incorrect.

Metadata

Metadata

Labels

area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.breaking-change-approvedbreaking-change-requestThis tracks requests for feedback on breaking changes

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions