Skip to content

proposal: use_of_instead_of_from for collections.Β #57106

@kevmoo

Description

@kevmoo

use_of_instead_of_from

Description

The from ctor on collections is more expensive. It does casts. If possible, use the of constructor.

Details

If the source collection has a known, compatible type statically, of should be used.

Kind

Performance.

Bad Examples

final slowList = List<int>.from(someIterableOfInt);

Good Examples

final fastList = List<int>.of(someIterableOfInt);

Discussion

This should apply to List, Set, Map and related subtypes.

See 6fae002

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposallinter-status-pendingtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions