From db36e559ff242b53fa15358dab1f174e771534f7 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 9 Sep 2022 19:20:03 -0700 Subject: [PATCH] Use toList(growable:false) more --- .../model_comment_reference.dart | 5 +-- lib/src/dartdoc_options.dart | 7 ++-- lib/src/generator/generator_frontend.dart | 2 +- lib/src/generator/generator_utils.dart | 4 +-- lib/src/markdown_processor.dart | 2 +- lib/src/model/canonicalization.dart | 3 +- lib/src/model/categorization.dart | 4 +-- lib/src/model/container.dart | 24 +++++++------ lib/src/model/documentation_comment.dart | 6 ++-- lib/src/model/inheriting_container.dart | 13 +++---- lib/src/model/method.dart | 2 +- lib/src/model/model_element.dart | 17 ++++----- lib/src/model/package.dart | 5 +-- lib/src/model/package_graph.dart | 35 +++++++++++-------- lib/src/model/top_level_container.dart | 26 +++++++------- lib/src/model/typedef.dart | 2 +- lib/src/mustachio/renderer_base.dart | 2 +- lib/src/package_meta.dart | 2 +- lib/src/render/model_element_renderer.dart | 3 +- lib/src/render/parameter_renderer.dart | 13 ++++--- lib/src/tool_runner.dart | 2 +- lib/src/warnings.dart | 2 +- 22 files changed, 101 insertions(+), 80 deletions(-) diff --git a/lib/src/comment_references/model_comment_reference.dart b/lib/src/comment_references/model_comment_reference.dart index 80c7f9182c..0fe38b9440 100644 --- a/lib/src/comment_references/model_comment_reference.dart +++ b/lib/src/comment_references/model_comment_reference.dart @@ -34,7 +34,8 @@ abstract class ModelCommentReference { /// and [ResourceProvider] after construction. class _ModelCommentReferenceImpl implements ModelCommentReference { void _initAllowCache() { - var referencePieces = parsed.whereType().toList(); + final referencePieces = + parsed.whereType().toList(growable: false); _allowUnnamedConstructor = false; _allowUnnamedConstructorParameter = false; if (referencePieces.length >= 2) { @@ -51,7 +52,7 @@ class _ModelCommentReferenceImpl implements ModelCommentReference { } } } - // e.g. [C.new], which may be the unnamed constructor + // e.g. [C.new], which may be the unnamed constructor. if (referencePieces.isNotEmpty && referencePieces.last.text == 'new') { _allowUnnamedConstructor = true; } diff --git a/lib/src/dartdoc_options.dart b/lib/src/dartdoc_options.dart index dd6cebd1f8..25be5e7eba 100644 --- a/lib/src/dartdoc_options.dart +++ b/lib/src/dartdoc_options.dart @@ -184,8 +184,9 @@ class ToolConfiguration { if (compileArgs is String) { args = [toolMap[compileArgsTagName].toString()]; } else if (compileArgs is YamlList) { - args = - compileArgs.map((node) => node.toString()).toList(); + args = compileArgs + .map((node) => node.toString()) + .toList(growable: false); } else { throw DartdocOptionError( 'Tool compile arguments must be a list of strings. The tool ' @@ -307,7 +308,7 @@ class _OptionValueWithContext { return (value as List) .map((v) => pathContext.canonicalizeWithTilde(v)) .cast() - .toList() as T; + .toList(growable: false) as T; } else if (value is String) { return pathContext.canonicalizeWithTilde(value as String) as T; } else if (value is Map) { diff --git a/lib/src/generator/generator_frontend.dart b/lib/src/generator/generator_frontend.dart index 5fa989bdc9..7d70d0f4cc 100644 --- a/lib/src/generator/generator_frontend.dart +++ b/lib/src/generator/generator_frontend.dart @@ -33,7 +33,7 @@ class GeneratorFrontEnd implements Generator { var categories = indexElements .whereType() .where((e) => e.hasCategorization) - .toList(); + .toList(growable: false); _generatorBackend.generateCategoryJson(categories); _generatorBackend.generateSearchIndex(indexElements); } diff --git a/lib/src/generator/generator_utils.dart b/lib/src/generator/generator_utils.dart index 59f3e990cf..6251b4b0af 100644 --- a/lib/src/generator/generator_utils.dart +++ b/lib/src/generator/generator_utils.dart @@ -31,7 +31,7 @@ String generateCategoryJson(Iterable categories, bool pretty) { final encoder = pretty ? const JsonEncoder.withIndent(' ') : const JsonEncoder(); - return encoder.convert(indexItems.toList()); + return encoder.convert(indexItems.toList(growable: false)); } String removeHtmlTags(String? input) { @@ -69,7 +69,7 @@ String generateSearchIndexJson( final encoder = pretty ? const JsonEncoder.withIndent(' ') : const JsonEncoder(); - return encoder.convert(indexItems.toList()); + return encoder.convert(indexItems); } // Compares two elements, first by fully qualified name, then by kind. diff --git a/lib/src/markdown_processor.dart b/lib/src/markdown_processor.dart index edcd3154fd..44b6956762 100644 --- a/lib/src/markdown_processor.dart +++ b/lib/src/markdown_processor.dart @@ -352,7 +352,7 @@ class MarkdownDocument extends md.Document { /// if [processFullText] is `true`. List parseMarkdownText(String text, {required bool processFullText}) { - var lines = LineSplitter.split(text).toList(); + var lines = LineSplitter.split(text).toList(growable: false); md.Node? firstNode; var nodes = []; // TODO(srawlins): Refactor this. I think with null safety, it is more clear diff --git a/lib/src/model/canonicalization.dart b/lib/src/model/canonicalization.dart index 0893452d07..b9b0798701 100644 --- a/lib/src/model/canonicalization.dart +++ b/lib/src/model/canonicalization.dart @@ -14,7 +14,8 @@ abstract class Canonicalization implements Locatable, Documentable { Set get locationPieces; List scoreCanonicalCandidates(Iterable libraries) { - return libraries.map(_scoreElementWithLibrary).toList()..sort(); + return libraries.map(_scoreElementWithLibrary).toList(growable: false) + ..sort(); } ScoredCandidate _scoreElementWithLibrary(Library lib) { diff --git a/lib/src/model/categorization.dart b/lib/src/model/categorization.dart index b2954fbd5c..54bf413abb 100644 --- a/lib/src/model/categorization.dart +++ b/lib/src/model/categorization.dart @@ -43,8 +43,8 @@ abstract class Categorization implements ModelElement { return ''; }); - _categoryNames = categorySet.toList()..sort(); - _subCategoryNames = subCategorySet.toList()..sort(); + _categoryNames = categorySet.toList(growable: false)..sort(); + _subCategoryNames = subCategorySet.toList(growable: false)..sort(); _image ??= ''; _samples ??= ''; return rawDocs; diff --git a/lib/src/model/container.dart b/lib/src/model/container.dart index 7ba052855c..8cba6d1dbf 100644 --- a/lib/src/model/container.dart +++ b/lib/src/model/container.dart @@ -73,7 +73,7 @@ abstract class Container extends ModelElement ]; late final List allCanonicalModelElements = - allModelElements.where((e) => e.isCanonical).toList(); + allModelElements.where((e) => e.isCanonical).toList(growable: false); /// All methods, including operators and statics, declared as part of this /// [Container]. @@ -108,7 +108,7 @@ abstract class Container extends ModelElement model_utils.filterNonPublic(instanceMethods); late final List publicInstanceMethodsSorted = - publicInstanceMethods.toList()..sort(); + publicInstanceMethods.toList(growable: false)..sort(); @nonVirtual late final Iterable declaredOperators = @@ -128,7 +128,7 @@ abstract class Container extends ModelElement model_utils.filterNonPublic(instanceOperators); late final List publicInstanceOperatorsSorted = - publicInstanceOperators.toList()..sort(); + publicInstanceOperators.toList(growable: false)..sort(); /// Fields fully declared in this [Container]. Iterable get declaredFields; @@ -147,7 +147,7 @@ abstract class Container extends ModelElement bool get hasPublicInstanceFields => publicInstanceFields.isNotEmpty; late final List publicInstanceFieldsSorted = - publicInstanceFields.toList()..sort(byName); + publicInstanceFields.toList(growable: false)..sort(byName); Iterable get constantFields => declaredFields.where((f) => f.isConst); @@ -157,7 +157,7 @@ abstract class Container extends ModelElement bool get hasPublicConstantFields => publicConstantFields.isNotEmpty; late final List publicConstantFieldsSorted = - publicConstantFields.toList()..sort(byName); + publicConstantFields.toList(growable: false)..sort(byName); Iterable get publicEnumValues => []; @@ -208,7 +208,7 @@ abstract class Container extends ModelElement bool get hasPublicStaticFields => publicStaticFieldsSorted.isNotEmpty; late final List publicStaticFieldsSorted = - model_utils.filterNonPublic(staticFields).toList()..sort(); + model_utils.filterNonPublic(staticFields).toList(growable: false)..sort(); Iterable get staticFields => declaredFields.where((f) => f.isStatic); @@ -218,8 +218,10 @@ abstract class Container extends ModelElement bool get hasPublicVariableStaticFields => publicVariableStaticFieldsSorted.isNotEmpty; - late final List publicVariableStaticFieldsSorted = - model_utils.filterNonPublic(variableStaticFields).toList()..sort(); + late final List publicVariableStaticFieldsSorted = model_utils + .filterNonPublic(variableStaticFields) + .toList(growable: false) + ..sort(); Iterable get staticMethods => declaredMethods.where((m) => m.isStatic); @@ -227,8 +229,10 @@ abstract class Container extends ModelElement bool get hasPublicStaticMethods => model_utils.filterNonPublic(publicStaticMethodsSorted).isNotEmpty; - late final List publicStaticMethodsSorted = - model_utils.filterNonPublic(staticMethods).toList()..sort(); + late final List publicStaticMethodsSorted = model_utils + .filterNonPublic(staticMethods) + .toList(growable: false) + ..sort(); /// For subclasses to add items after the main pass but before the /// parameter-global. diff --git a/lib/src/model/documentation_comment.dart b/lib/src/model/documentation_comment.dart index 1053e52d1a..64f08ae967 100644 --- a/lib/src/model/documentation_comment.dart +++ b/lib/src/model/documentation_comment.dart @@ -258,7 +258,7 @@ mixin DocumentationComment var invocationIndex = 0; return await _replaceAllMappedAsync(rawDocs, _basicToolPattern, (basicMatch) async { - var args = _splitUpQuotedArgs(basicMatch[1]!).toList(); + final args = _splitUpQuotedArgs(basicMatch[1]!); // Tool name must come first. if (args.isEmpty) { warn(PackageWarning.toolError, @@ -268,8 +268,8 @@ mixin DocumentationComment // Count the number of invocations of tools in this dartdoc block, // so that tools can differentiate different blocks from each other. invocationIndex++; - return await config.tools.runner.run(args, content: basicMatch[2]!, - toolErrorCallback: (String message) async { + return await config.tools.runner.run(args.toList(), + content: basicMatch[2]!, toolErrorCallback: (String message) async { warn(PackageWarning.toolError, message: message); }, environment: _toolsEnvironment(invocationIndex: invocationIndex)); }); diff --git a/lib/src/model/inheriting_container.dart b/lib/src/model/inheriting_container.dart index 1539847998..194e6d48a6 100644 --- a/lib/src/model/inheriting_container.dart +++ b/lib/src/model/inheriting_container.dart @@ -28,7 +28,7 @@ mixin Constructable on InheritingContainer { @override late final List publicConstructorsSorted = - model_utils.filterNonPublic(constructors).toList()..sort(); + model_utils.filterNonPublic(constructors).toList(growable: false)..sort(); static Iterable> _constructorGenerator( Iterable source) sync* { @@ -171,7 +171,8 @@ mixin TypeImplementing on InheritingContainer { List? _publicImplementorsSorted; Iterable get publicImplementorsSorted => - _publicImplementorsSorted ??= publicImplementors.toList()..sort(byName); + _publicImplementorsSorted ??= publicImplementors.toList(growable: false) + ..sort(byName); } /// A [Container] that participates in inheritance in Dart. @@ -354,7 +355,7 @@ abstract class InheritingContainer extends Container // Elements in the inheritance chain starting from [this.element] // down to, but not including, [Object]. inheritanceChainElements ??= - inheritanceChain.map((c) => c!.element).toList(); + inheritanceChain.map((c) => c!.element).toList(growable: false); // [packageGraph.specialClasses] is not available yet. bool isDartCoreObject(ClassElement e) => e.name == 'Object' && e.library.name == 'dart.core'; @@ -379,7 +380,7 @@ abstract class InheritingContainer extends Container } } - __inheritedElements = combinedMap.values.toList(); + __inheritedElements = combinedMap.values.toList(growable: false); } return __inheritedElements; } @@ -419,7 +420,7 @@ abstract class InheritingContainer extends Container // Now we only have inherited accessors who aren't associated with // anything in cls._fields. for (var fieldName in accessorMap.keys) { - var elements = accessorMap[fieldName]!.toList(); + var elements = accessorMap[fieldName]!.toList(growable: false); var getterElement = elements.firstWhereOrNull((e) => e.isGetter); var setterElement = elements.firstWhereOrNull((e) => e.isSetter); fields.add(_createSingleField( @@ -519,7 +520,7 @@ abstract class InheritingContainer extends Container _typeParameters ??= element.typeParameters.map((f) { var lib = modelBuilder.fromElement(f.enclosingElement3!.library!); return modelBuilder.from(f, lib as Library) as TypeParameter; - }).toList(); + }).toList(growable: false); return _typeParameters!; } diff --git a/lib/src/model/method.dart b/lib/src/model/method.dart index 6f15ac7793..b34623bb31 100644 --- a/lib/src/model/method.dart +++ b/lib/src/model/method.dart @@ -34,7 +34,7 @@ class Method extends ModelElement void _calcTypeParameters() { typeParameters = element.typeParameters.map((f) { return modelBuilder.from(f, library) as TypeParameter; - }).toList(); + }).toList(growable: false); } @override diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 191e96dba9..0c71aa7dab 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -570,7 +570,7 @@ abstract class ModelElement extends Canonicalization topLevelElement = topLevelElement.enclosingElement3!; } - var candidateLibraries = thisAndExported + final candidateLibraries = thisAndExported .where((l) => l.isPublic && l.package.documentedWhere != DocumentLocation.missing) .where((l) { @@ -580,7 +580,7 @@ abstract class ModelElement extends Canonicalization lookup = lookup.variable; } return topLevelElement == lookup; - }).toList(); + }).toList(growable: true); // Avoid claiming canonicalization for elements outside of this element's // defining package. @@ -609,21 +609,22 @@ abstract class ModelElement extends Canonicalization // canonical. Still warn if the heuristic isn't that confident. var scoredCandidates = warnable.scoreCanonicalCandidates(candidateLibraries); - candidateLibraries = scoredCandidates.map((s) => s.library).toList(); + final librariesByScore = scoredCandidates.map((s) => s.library).toList(); var secondHighestScore = scoredCandidates[scoredCandidates.length - 2].score; var highestScore = scoredCandidates.last.score; var confidence = highestScore - secondHighestScore; + final canonicalLibrary = librariesByScore.last; if (confidence < config.ambiguousReexportScorerMinConfidence) { - var libraryNames = candidateLibraries.map((l) => l.name); - var message = '$libraryNames -> ${candidateLibraries.last.name} ' + var libraryNames = librariesByScore.map((l) => l.name); + var message = '$libraryNames -> ${canonicalLibrary.name} ' '(confidence ${confidence.toStringAsPrecision(4)})'; warnable.warn(PackageWarning.ambiguousReexport, message: message, extendedDebug: scoredCandidates.map((s) => '$s')); } - return candidateLibraries.last; + return canonicalLibrary; } @override @@ -737,7 +738,7 @@ abstract class ModelElement extends Canonicalization var setterDeprecated = pie.setter?.metadata.any((a) => a.isDeprecated); var deprecatedValues = - [getterDeprecated, setterDeprecated].whereNotNull().toList(); + [getterDeprecated, setterDeprecated].whereNotNull(); // At least one of these should be non-null. Otherwise things are weird assert(deprecatedValues.isNotEmpty); @@ -854,7 +855,7 @@ abstract class ModelElement extends Canonicalization } } } - return recursedParameters.toList(); + return recursedParameters.toList(growable: false); }(); @override diff --git a/lib/src/model/package.dart b/lib/src/model/package.dart index 5718705edc..879397bfaa 100644 --- a/lib/src/model/package.dart +++ b/lib/src/model/package.dart @@ -329,7 +329,7 @@ class Package extends LibraryContainer late final List categories = [ defaultCategory, ...nameToCategory.values, - ].where((c) => c.name.isNotEmpty).toList() + ].where((c) => c.name.isNotEmpty).toList(growable: false) ..sort(); Iterable get categoriesWithPublicLibraries => @@ -346,7 +346,8 @@ class Package extends LibraryContainer /// ordered by name. Iterable get documentedCategoriesSorted { if (config.categoryOrder.isNotEmpty) { - final documentedCategories = this.documentedCategories.toList(); + final documentedCategories = + this.documentedCategories.toList(growable: false); return documentedCategories ..sort((a, b) { var aIndex = config.categoryOrder.indexOf(a.name); diff --git a/lib/src/model/package_graph.dart b/lib/src/model/package_graph.dart index 96e11ee374..c24ee9bc16 100644 --- a/lib/src/model/package_graph.dart +++ b/lib/src/model/package_graph.dart @@ -486,7 +486,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { return locatable.fullyQualifiedName.replaceFirst(':', '-'); } - List get packages => packageMap.values.toList(); + List get packages => packageMap.values.toList(growable: false); late final List publicPackages = () { assert(allLibrariesAdded); @@ -498,12 +498,12 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { message: "$packageName, packages: ${packageNames.join(',')}"); } } - return packages.where((p) => p.isPublic).toList()..sort(); + return packages.where((p) => p.isPublic).toList(growable: false)..sort(); }(); /// Local packages are to be documented locally vs. remote or not at all. List get localPackages => - publicPackages.where((p) => p.isLocal).toList(); + publicPackages.where((p) => p.isLocal).toList(growable: false); /// Documented packages are documented somewhere (local or remote). Iterable get documentedPackages => @@ -644,7 +644,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { @visibleForTesting late final Iterable libraries = - packages.expand((p) => p.libraries).toList()..sort(); + packages.expand((p) => p.libraries).toList(growable: false)..sort(); /// The number of libraries. late final int libraryCount = libraries.length; @@ -656,7 +656,8 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { late final List _localLibraries = () { assert(allLibrariesAdded); - return localPackages.expand((p) => p.libraries).toList()..sort(); + return localPackages.expand((p) => p.libraries).toList(growable: false) + ..sort(); }(); late final Set localPublicLibraries = () { @@ -812,13 +813,15 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { })); } - var matches = {...candidates.where((me) => me.isCanonical)}; + var matches = {...candidates.where((me) => me.isCanonical)}; // It's possible to find accessors but no combos. Be sure that if we // have Accessors, we find their combos too. if (matches.any((me) => me is Accessor)) { - var combos = - matches.whereType().map((a) => a.enclosingCombo).toList(); + var combos = matches + .whereType() + .map((a) => a.enclosingCombo) + .toList(growable: false); matches.addAll(combos); assert(combos.every((c) => c.isCanonical)); } @@ -827,11 +830,12 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { // for an inherited element whose defining Class is not canonical. if (matches.length > 1 && preferredClass != null) { // Search for matches inside our superchain. - var superChain = preferredClass.superChain - .map((et) => et.modelElement) - .cast() - .toList(); - superChain.add(preferredClass); + var superChain = [ + for (final elementType in preferredClass.superChain) + elementType.modelElement as InheritingContainer, + preferredClass, + ]; + matches.removeWhere((me) => !superChain.contains(me.enclosingElement)); // Assumed all matches are EnclosedElement because we've been told about a // preferredClass. @@ -991,8 +995,9 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { // We have to use a stable order or otherwise references depending // on ambiguous resolution (see below) will change where they // resolve based on internal implementation details. - var sortedPackages = packages.toList()..sort(byName); - var sortedDocumentedPackages = documentedPackages.toList()..sort(byName); + var sortedPackages = packages.toList(growable: false)..sort(byName); + var sortedDocumentedPackages = documentedPackages.toList(growable: false) + ..sort(byName); // Packages are the top priority. children.addEntries(sortedPackages.generateEntries()); diff --git a/lib/src/model/top_level_container.dart b/lib/src/model/top_level_container.dart index b667c270be..cfef3a9f7f 100644 --- a/lib/src/model/top_level_container.dart +++ b/lib/src/model/top_level_container.dart @@ -53,49 +53,51 @@ abstract class TopLevelContainer implements Nameable { // TODO(jcollins-g): Setting this type parameter to `Container` magically // fixes a number of type problems in the AOT compiler, but I am mystified as // to why that should be the case. - late final Iterable publicClassesSorted = publicClasses.toList() - ..sort(); + late final Iterable publicClassesSorted = + publicClasses.toList(growable: false)..sort(); Iterable get publicExtensions => model_utils.filterNonPublic(extensions); late final Iterable publicExtensionsSorted = - publicExtensions.toList()..sort(); + publicExtensions.toList(growable: false)..sort(); Iterable get publicConstants => model_utils.filterNonPublic(constants); Iterable get publicConstantsSorted => - publicConstants.toList()..sort(); + publicConstants.toList(growable: false)..sort(); Iterable get publicEnums => model_utils.filterNonPublic(enums); - late final Iterable publicEnumsSorted = publicEnums.toList()..sort(); + late final Iterable publicEnumsSorted = + publicEnums.toList(growable: false)..sort(); Iterable get _publicExceptions => model_utils.filterNonPublic(exceptions); - late final Iterable publicExceptionsSorted = _publicExceptions.toList() - ..sort(); + late final Iterable publicExceptionsSorted = + _publicExceptions.toList(growable: false)..sort(); Iterable get publicFunctions => model_utils.filterNonPublic(functions!); late final Iterable publicFunctionsSorted = - publicFunctions.toList()..sort(); + publicFunctions.toList(growable: false)..sort(); Iterable get publicMixins => model_utils.filterNonPublic(mixins); - late final Iterable publicMixinsSorted = publicMixins.toList()..sort(); + late final Iterable publicMixinsSorted = + publicMixins.toList(growable: false)..sort(); Iterable get publicProperties => model_utils.filterNonPublic(properties); late final Iterable publicPropertiesSorted = - publicProperties.toList()..sort(); + publicProperties.toList(growable: false)..sort(); Iterable get publicTypedefs => model_utils.filterNonPublic(typedefs); - late final Iterable publicTypedefsSorted = publicTypedefs.toList() - ..sort(); + late final Iterable publicTypedefsSorted = + publicTypedefs.toList(growable: false)..sort(); } diff --git a/lib/src/model/typedef.dart b/lib/src/model/typedef.dart index 4bef74b9ce..4531651a74 100644 --- a/lib/src/model/typedef.dart +++ b/lib/src/model/typedef.dart @@ -62,7 +62,7 @@ abstract class Typedef extends ModelElement @override List get typeParameters => element.typeParameters .map((f) => modelBuilder.from(f, library) as TypeParameter) - .toList(); + .toList(growable: false); TypedefRenderer get _renderer => packageGraph.rendererFactory.typedefRenderer; diff --git a/lib/src/mustachio/renderer_base.dart b/lib/src/mustachio/renderer_base.dart index 761e4c8fb6..3e47a7e5d6 100644 --- a/lib/src/mustachio/renderer_base.dart +++ b/lib/src/mustachio/renderer_base.dart @@ -263,7 +263,7 @@ abstract class RendererBase { // An inverted section is rendered with the current context. renderBlock(node.children); } else if (!node.invert && renderedIterable.isNotEmpty) { - renderedIterable.toList(); + renderedIterable.toList(growable: false); } // Otherwise, render nothing. diff --git a/lib/src/package_meta.dart b/lib/src/package_meta.dart index aa35fae28d..4d2921087c 100644 --- a/lib/src/package_meta.dart +++ b/lib/src/package_meta.dart @@ -396,7 +396,7 @@ class _FilePackageMeta extends PubPackageMeta { } File? _locate(Folder dir, List fileNames) { - var files = dir.getChildren().whereType().toList(); + var files = dir.getChildren().whereType().toList(growable: false); for (var name in fileNames) { for (var f in files) { diff --git a/lib/src/render/model_element_renderer.dart b/lib/src/render/model_element_renderer.dart index fc8da46c96..6dbffdf15d 100644 --- a/lib/src/render/model_element_renderer.dart +++ b/lib/src/render/model_element_renderer.dart @@ -16,7 +16,8 @@ abstract class ModelElementRenderer { String uniqueId, int width, int height, Uri movieUrl, String overlayId); String renderFeatures(ModelElement modelElement) { - var allFeatures = modelElement.features.toList()..sort(byFeatureOrdering); + var allFeatures = modelElement.features.toList(growable: false) + ..sort(byFeatureOrdering); return allFeatures .map((f) => '${f.linkedNameWithParameters}') diff --git a/lib/src/render/parameter_renderer.dart b/lib/src/render/parameter_renderer.dart index 7ef40eff27..7571f0aedb 100644 --- a/lib/src/render/parameter_renderer.dart +++ b/lib/src/render/parameter_renderer.dart @@ -97,11 +97,14 @@ abstract class ParameterRenderer { String renderLinkedParams(List parameters, {bool showMetadata = true, bool showNames = true}) { - var positionalParams = - parameters.where((Parameter p) => p.isRequiredPositional).toList(); - var optionalPositionalParams = - parameters.where((Parameter p) => p.isOptionalPositional).toList(); - var namedParams = parameters.where((Parameter p) => p.isNamed).toList(); + var positionalParams = parameters + .where((Parameter p) => p.isRequiredPositional) + .toList(growable: false); + var optionalPositionalParams = parameters + .where((Parameter p) => p.isOptionalPositional) + .toList(growable: false); + var namedParams = + parameters.where((Parameter p) => p.isNamed).toList(growable: false); var output = StringBuffer(); if (positionalParams.isNotEmpty) { diff --git a/lib/src/tool_runner.dart b/lib/src/tool_runner.dart index cd7e941dda..36e177ac04 100644 --- a/lib/src/tool_runner.dart +++ b/lib/src/tool_runner.dart @@ -73,7 +73,7 @@ class ToolRunner { Map environment, ToolErrorCallback toolErrorCallback) async { var isDartSetup = ToolDefinition.isDartExecutable(tool.setupCommand[0]); - var args = tool.setupCommand.toList(); + var args = tool.setupCommand.toList(growable: true); String commandPath; if (isDartSetup) { diff --git a/lib/src/warnings.dart b/lib/src/warnings.dart index 3141041df7..b8c904525f 100644 --- a/lib/src/warnings.dart +++ b/lib/src/warnings.dart @@ -87,7 +87,7 @@ List> createPackageWarningOptions( String _warningsListHelpText(PackageWarningMode mode) { return (packageWarningDefinitions.values .where((d) => d.defaultWarningMode == mode) - .toList() + .toList(growable: false) ..sort()) .map((d) => ' ${d.warningName}: ${d.shortHelp}') .join('\n');