@@ -28,13 +28,15 @@ public static ParserResult<T> Build<T>(
2828 var typeInfo = factory . MapValueOrDefault ( f => f ( ) . GetType ( ) , typeof ( T ) ) ;
2929
3030 var specProps = typeInfo . GetSpecifications ( pi => SpecificationProperty . Create (
31- Specification . FromProperty ( pi ) , pi , Maybe . Nothing < object > ( ) ) ) ;
31+ Specification . FromProperty ( pi ) , pi , Maybe . Nothing < object > ( ) ) )
32+ . Memorize ( ) ;
3233
3334 var specs = from pt in specProps select pt . Specification ;
3435
3536 var optionSpecs = specs
3637 . ThrowingValidate ( SpecificationGuards . Lookup )
37- . OfType < OptionSpecification > ( ) ;
38+ . OfType < OptionSpecification > ( )
39+ . Memorize ( ) ;
3840
3941 Func < T > makeDefault = ( ) =>
4042 typeof ( T ) . IsMutable ( )
@@ -45,18 +47,19 @@ public static ParserResult<T> Build<T>(
4547 Func < IEnumerable < Error > , ParserResult < T > > notParsed =
4648 errs => new NotParsed < T > ( makeDefault ( ) . GetType ( ) . ToTypeInfo ( ) , errs ) ;
4749
50+ var argumentsList = arguments . Memorize ( ) ;
4851 Func < ParserResult < T > > buildUp = ( ) =>
4952 {
50- var tokenizerResult = tokenizer ( arguments , optionSpecs ) ;
53+ var tokenizerResult = tokenizer ( argumentsList , optionSpecs ) ;
5154
52- var tokens = tokenizerResult . SucceededWith ( ) ;
55+ var tokens = tokenizerResult . SucceededWith ( ) . Memorize ( ) ;
5356
5457 var partitions = TokenPartitioner . Partition (
5558 tokens ,
5659 name => TypeLookup . FindTypeDescriptorAndSibling ( name , optionSpecs , nameComparer ) ) ;
57- var optionsPartition = partitions . Item1 ;
58- var valuesPartition = partitions . Item2 ;
59- var errorsPartition = partitions . Item3 ;
60+ var optionsPartition = partitions . Item1 . Memorize ( ) ;
61+ var valuesPartition = partitions . Item2 . Memorize ( ) ;
62+ var errorsPartition = partitions . Item3 . Memorize ( ) ;
6063
6164 var optionSpecPropsResult =
6265 OptionMapper . MapValues (
@@ -68,7 +71,7 @@ public static ParserResult<T> Build<T>(
6871 var valueSpecPropsResult =
6972 ValueMapper . MapValues (
7073 ( from pt in specProps where pt . Specification . IsValue ( ) orderby ( ( ValueSpecification ) pt . Specification ) . Index select pt ) ,
71- valuesPartition ,
74+ valuesPartition ,
7275 ( vals , type , isScalar ) => TypeConverter . ChangeType ( vals , type , isScalar , parsingCulture , ignoreValueCase ) ) ;
7376
7477 var missingValueErrors = from token in errorsPartition
@@ -78,7 +81,7 @@ public static ParserResult<T> Build<T>(
7881 . FromOptionSpecification ( ) ) ;
7982
8083 var specPropsWithValue =
81- optionSpecPropsResult . SucceededWith ( ) . Concat ( valueSpecPropsResult . SucceededWith ( ) ) ;
84+ optionSpecPropsResult . SucceededWith ( ) . Concat ( valueSpecPropsResult . SucceededWith ( ) ) . Memorize ( ) ;
8285
8386 var setPropertyErrors = new List < Error > ( ) ;
8487
@@ -130,11 +133,13 @@ join sp in specPropsWithValue on prms.Name.ToLower() equals sp.Property.Name.ToL
130133 return allErrors . Except ( warnings ) . ToParserResult ( instance ) ;
131134 } ;
132135
133- var preprocessorErrors = arguments . Any ( )
134- ? arguments . Preprocess ( PreprocessorGuards . Lookup ( nameComparer ) )
135- : Enumerable . Empty < Error > ( ) ;
136+ var preprocessorErrors = (
137+ argumentsList . Any ( )
138+ ? argumentsList . Preprocess ( PreprocessorGuards . Lookup ( nameComparer ) )
139+ : Enumerable . Empty < Error > ( )
140+ ) . Memorize ( ) ;
136141
137- var result = arguments . Any ( )
142+ var result = argumentsList . Any ( )
138143 ? preprocessorErrors . Any ( )
139144 ? notParsed ( preprocessorErrors )
140145 : buildUp ( )
0 commit comments