@@ -651,25 +651,50 @@ class FunctionType extends DartType {
651651
652652 final List <FunctionTypeVariable > typeVariables;
653653
654- FunctionType ._ (
654+ FunctionType ._allocate (
655655 this .returnType,
656656 this .parameterTypes,
657657 this .optionalParameterTypes,
658658 this .namedParameters,
659659 this .requiredNamedParameters,
660660 this .namedParameterTypes,
661661 this .typeVariables) {
662- assert (returnType != null , " Invalid return type in $this ." );
663- assert (! parameterTypes.contains (null ), " Invalid parameter types in $this ." );
662+ assert (returnType != null , ' Invalid return type in $this .' );
663+ assert (! parameterTypes.contains (null ), ' Invalid parameter types in $this .' );
664664 assert (! optionalParameterTypes.contains (null ),
665- " Invalid optional parameter types in $this ." );
665+ ' Invalid optional parameter types in $this .' );
666666 assert (
667- ! namedParameters.contains (null ), " Invalid named parameters in $this ." );
667+ ! namedParameters.contains (null ), ' Invalid named parameters in $this .' );
668668 assert (! requiredNamedParameters.contains (null ),
669- " Invalid required named parameters in $this ." );
669+ ' Invalid required named parameters in $this .' );
670670 assert (! namedParameterTypes.contains (null ),
671- "Invalid named parameter types in $this ." );
672- assert (! typeVariables.contains (null ), "Invalid type variables in $this ." );
671+ 'Invalid named parameter types in $this .' );
672+ assert (! typeVariables.contains (null ), 'Invalid type variables in $this .' );
673+ }
674+
675+ factory FunctionType ._(
676+ DartType returnType,
677+ List <DartType > parameterTypes,
678+ List <DartType > optionalParameterTypes,
679+ List <String > namedParameters,
680+ Set <String > requiredNamedParameters,
681+ List <DartType > namedParameterTypes,
682+ List <FunctionTypeVariable > typeVariables) {
683+ // Canonicalize empty collections to constants to save storage.
684+ if (parameterTypes.isEmpty) parameterTypes = const [];
685+ if (optionalParameterTypes.isEmpty) optionalParameterTypes = const [];
686+ if (namedParameterTypes.isEmpty) namedParameterTypes = const [];
687+ if (requiredNamedParameters.isEmpty) requiredNamedParameters = const {};
688+ if (typeVariables.isEmpty) typeVariables = const [];
689+
690+ return FunctionType ._allocate (
691+ returnType,
692+ parameterTypes,
693+ optionalParameterTypes,
694+ namedParameters,
695+ requiredNamedParameters,
696+ namedParameterTypes,
697+ typeVariables);
673698 }
674699
675700 factory FunctionType ._readFromDataSource (
0 commit comments