@@ -651,25 +651,50 @@ class FunctionType extends DartType {
651
651
652
652
final List <FunctionTypeVariable > typeVariables;
653
653
654
- FunctionType ._ (
654
+ FunctionType ._allocate (
655
655
this .returnType,
656
656
this .parameterTypes,
657
657
this .optionalParameterTypes,
658
658
this .namedParameters,
659
659
this .requiredNamedParameters,
660
660
this .namedParameterTypes,
661
661
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 .' );
664
664
assert (! optionalParameterTypes.contains (null ),
665
- " Invalid optional parameter types in $this ." );
665
+ ' Invalid optional parameter types in $this .' );
666
666
assert (
667
- ! namedParameters.contains (null ), " Invalid named parameters in $this ." );
667
+ ! namedParameters.contains (null ), ' Invalid named parameters in $this .' );
668
668
assert (! requiredNamedParameters.contains (null ),
669
- " Invalid required named parameters in $this ." );
669
+ ' Invalid required named parameters in $this .' );
670
670
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);
673
698
}
674
699
675
700
factory FunctionType ._readFromDataSource (
0 commit comments