Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd4ecae

Browse files
authoredOct 14, 2024
Avoid dynamically typed .from methods (#8147)
1 parent fe0a863 commit dd4ecae

File tree

13 files changed

+18
-20
lines changed

13 files changed

+18
-20
lines changed
 

‎app/lib/admin/tools/delete_all_staging.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Future<void> _batchedQuery<T extends Model>(
8787

8888
void flush() {
8989
if (keys.isEmpty) return;
90-
fn(List.from(keys));
90+
fn(List.of(keys));
9191
keys.clear();
9292
budget = _defaultBudget;
9393
}

‎app/lib/frontend/handlers/account.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ Future<LikedPackagesResponse> listPackageLikesHandler(
203203
final authenticatedUser = await requireAuthenticatedWebUser();
204204
final user = authenticatedUser.user;
205205
final packages = await likeBackend.listPackageLikes(user);
206-
final List<PackageLikeResponse> packageLikes = List.from(packages.map(
207-
(like) => PackageLikeResponse(
208-
liked: true, package: like.package, created: like.created)));
206+
final List<PackageLikeResponse> packageLikes = packages
207+
.map((like) => PackageLikeResponse(
208+
liked: true, package: like.package, created: like.created))
209+
.toList();
209210
return LikedPackagesResponse(likedPackages: packageLikes);
210211
}
211212

‎app/lib/frontend/handlers/custom_api.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,7 @@ Future<shelf.Response> apiSearchHandler(shelf.Request request) async {
461461
if (sr.errorMessage != null) 'message': sr.errorMessage,
462462
};
463463
if (hasNextPage) {
464-
final newParams =
465-
Map<String, dynamic>.from(request.requestedUri.queryParameters);
464+
final newParams = {...request.requestedUri.queryParameters};
466465
newParams['page'] = (searchForm.currentPage! + 1).toString();
467466
final nextPageUrl =
468467
request.requestedUri.replace(queryParameters: newParams).toString();

‎app/lib/frontend/static_files.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class StaticFileCache {
200200
String get etag => _etag ??= _calculateEtagOfEtags().substring(0, 8);
201201

202202
String _calculateEtagOfEtags() {
203-
final files = List<StaticFile>.from(_files.values);
203+
final files = _files.values.toList();
204204
files.sort((a, b) => a.requestPath.compareTo(b.requestPath));
205205
final concatenatedEtags = files.map((f) => f.etag).join(' ');
206206
final digest = crypto.sha256.convert(utf8.encode(concatenatedEtags));
@@ -402,8 +402,7 @@ class ParsedStaticUrl {
402402

403403
factory ParsedStaticUrl.parse(Uri requestedUri) {
404404
final normalizedRequestPath = path.normalize(requestedUri.path);
405-
final pathSegments =
406-
List<String>.from(Uri(path: normalizedRequestPath).pathSegments);
405+
final pathSegments = List.of(Uri(path: normalizedRequestPath).pathSegments);
407406
String? pathHash;
408407
var filePath = normalizedRequestPath;
409408
if (pathSegments.length > 2 && pathSegments[1].startsWith('hash-')) {

‎app/lib/search/models.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:clock/clock.dart';
6+
import 'package:collection/collection.dart';
67
import 'package:json_annotation/json_annotation.dart';
78
import 'package:pub_dev/shared/popularity_storage.dart';
89

@@ -59,8 +60,7 @@ extension UpdateLikesExt on Iterable<PackageDocument> {
5960
/// The score is normalized into the range of [0.0 - 1.0] using the
6061
/// ordered list of packages by like counts (same like count gets the same score).
6162
void updateLikeScores() {
62-
final sortedByLikes = List<PackageDocument>.from(this)
63-
..sort((a, b) => a.likeCount.compareTo(b.likeCount));
63+
final sortedByLikes = sorted((a, b) => a.likeCount.compareTo(b.likeCount));
6464
for (var i = 0; i < sortedByLikes.length; i++) {
6565
if (i > 0 &&
6666
sortedByLikes[i - 1].likeCount == sortedByLikes[i].likeCount) {

‎app/lib/search/search_service.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class PackageDocument {
128128
Map<String, dynamic> toJson() => _$PackageDocumentToJson(this);
129129

130130
@JsonKey(includeFromJson: false, includeToJson: false)
131-
late final tagsForLookup = Set<String>.from(tags);
131+
late final Set<String> tagsForLookup = Set.of(tags);
132132
}
133133

134134
/// A reference to an API doc page

‎app/lib/service/youtube/backend.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class YoutubeBackend {
8282
/// Algorithm description at [YoutubeBackend.getTopPackageOfWeekVideos].
8383
@visibleForTesting
8484
List<T> selectRandomVideos<T>(math.Random random, List<T> source, int count) {
85-
final selectable = List<T>.from(source);
85+
final selectable = List.of(source);
8686
final selected = <T>[];
8787
while (selected.length < count && selectable.isNotEmpty) {
8888
if (selected.isEmpty) {

‎app/lib/shared/configuration.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:convert' show json;
66
import 'dart:io';
77

8-
import 'package:collection/collection.dart' show UnmodifiableSetView;
98
import 'package:gcloud/service_scope.dart' as ss;
109
import 'package:json_annotation/json_annotation.dart';
1110
import 'package:meta/meta.dart';
@@ -454,7 +453,7 @@ class AdminId {
454453
required this.oauthUserId,
455454
required this.email,
456455
required Iterable<AdminPermission?> permissions,
457-
}) : permissions = UnmodifiableSetView(Set.from(permissions));
456+
}) : permissions = Set.unmodifiable(permissions.nonNulls);
458457

459458
factory AdminId.fromJson(Map<String, dynamic> json) =>
460459
_$AdminIdFromJson(json);

‎app/lib/shared/markdown.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ String _rewriteAbsoluteUrl(String url) {
318318
if (uri.host == 'github.com') {
319319
final segments = uri.pathSegments;
320320
if (segments.length > 3 && segments[2] == 'blob') {
321-
final newSegments = List<String>.from(segments);
321+
final newSegments = List.of(segments);
322322
newSegments[2] = 'raw';
323323
return uri.replace(pathSegments: newSegments).toString();
324324
}

‎app/lib/shared/urls.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ String? getRepositoryUrl(
398398
}
399399
try {
400400
final uri = Uri.parse(repository!);
401-
final segments = List<String>.from(uri.pathSegments);
401+
final segments = List.of(uri.pathSegments);
402402
while (segments.isNotEmpty && segments.last.isEmpty) {
403403
segments.removeLast();
404404
}

‎app/lib/shared/utils.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class LastNTracker<T extends Comparable<T>> {
135135

136136
T? _getP(double p) {
137137
if (_lastItems.isEmpty) return null;
138-
final List<T> list = List.from(_lastItems);
138+
final List<T> list = _lastItems.toList();
139139
list.sort();
140140
return list[(list.length * p).floor()];
141141
}

‎app/lib/task/cloudcompute/googlecloudcompute.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ final class _GoogleCloudCompute extends CloudCompute {
356356
);
357357

358358
@override
359-
List<String> get zones => List.from(_zones);
359+
List<String> get zones => List.of(_zones);
360360

361361
@override
362362
String generateInstanceName() => 'worker-${Ulid()}';

‎pkg/fake_gcloud/lib/mem_datastore.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MemDatastore implements Datastore {
2121
Future<List<Key>> allocateIds(List<Key> keys) async {
2222
return keys.map((k) {
2323
if (k.elements.last.id == null) {
24-
final elements = List<KeyElement>.from(k.elements);
24+
final elements = List.of(k.elements);
2525
final last = elements.removeLast();
2626
elements.add(KeyElement(last.kind, _unusedId++));
2727
return Key(elements, partition: k.partition);

0 commit comments

Comments
 (0)
Failed to load comments.