Skip to content
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

Use ??= over contains and ! for map defaulting #3241

Merged
merged 1 commit into from Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_modules/CHANGELOG.md
@@ -1,3 +1,5 @@
## 4.0.5-dev

## 4.0.4

- Allow the latest analyzer.
Expand Down
13 changes: 6 additions & 7 deletions build_modules/lib/src/meta_module.dart
Expand Up @@ -238,14 +238,13 @@ MetaModule _coarseModulesForLibraries(
var librariesByDirectory = <String, Map<AssetId, ModuleLibrary>>{};
for (var library in libraries) {
final dir = _topLevelDir(library.id.path);
if (!librariesByDirectory.containsKey(dir)) {
librariesByDirectory[dir] = <AssetId, ModuleLibrary>{};
}
librariesByDirectory[dir]![library.id] = library;
(librariesByDirectory[dir] ??= {})[library.id] = library;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use putIfAbsent also, but 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had thought about that pattern too but for some reason ??= looked nicer to me.

Maybe it was something like dart2js emitting better code for ??= than putIfAbsent? (even though this will not be compiled with dart2js)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would usually use putIfAbsent, it's true that this doesn't require a closure though. I am fine with either way.

}
final modules = librariesByDirectory.values
.expand((libs) => _computeModules(libs, platform))
.toList();

final modules = [
for (var libraries in librariesByDirectory.values)
..._computeModules(libraries, platform)
];
_sortModules(modules);
return MetaModule(modules);
}
Expand Down
2 changes: 1 addition & 1 deletion build_modules/pubspec.yaml
@@ -1,5 +1,5 @@
name: build_modules
version: 4.0.4
version: 4.0.5-dev
description: Builders for Dart modules
repository: https://github.com/dart-lang/build/tree/master/build_modules

Expand Down