dart-lang / dart-lang/language

Make it easy/efficient to create immutable collections via literals

Open
#117 5 comments 25 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

See

https://github.com/dart-lang/sdk/blob/031e77eea11a16a5e486a3673549adbd68862c8e/sdk/lib/core/uri.dart#L2233-L2237

```dart
// ASCII, a single percent encoded sequence.
codeUnits = new List(3);
codeUnits[0] = _PERCENT;
codeUnits[1] = _hexDigits.codeUnitAt(char >> 4);
codeUnits[2] = _hexDigits.codeUnitAt(char & 0xf);
```

Also in the SDK,
2x in this file https://github.com/dart-lang/sdk/blob/031e77eea11a16a5e486a3673549adbd68862c8e/sdk/lib/vmservice/message.dart#L176-L182

4x in this file https://github.com/dart-lang/sdk/blob/031e77eea11a16a5e486a3673549adbd68862c8e/runtime/bin/vmservice/loader.dart#L1107-L1112

This entire file in `pkg:isolate` - https://github.com/dart-lang/isolate/blob/master/lib/src/util.dart

In the Dart sources in Google (some of these duplicate the above)

- `List.unmodifiable\(\[` - 135 hits
- `List\<.+\>\.unmodifiable\(\[` - 96 times
- `Map\<.+,.+>\.unmodifiable\(\{` - 25 times
- `Map\.unmodifiable\(\{` - 28 times
- `UnmodifiableSetView` from `pkg:collection` is used dozens of times, not as a view over mutable data, but as a immutable set.

Benefits:

- Less copying!
- Immutable collections are more efficient
- iteration doesn't need to track `version`, etc
- no need to have indirection to a fixed-sized backing store to support growing
- Enables special-casing implementations - e.g. `immutable([1,2,3])` could be created as `Uint8List`.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the linked SDK examples and the collection usage counts in the issue, including sdk/lib/core/uri.dart, sdk/lib/vmservice/message.dart, runtime/bin/vmservice/loader.dart, and pkg:isolate/lib/src/util.dart. Determine the literal syntax, semantics, and implementation scope needed; the work is done when the language proposal resolves these design questions and identifies the affected collection behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.