@@ -28,13 +28,15 @@ public static ParserResult<T> Build<T>(
28
28
var typeInfo = factory . MapValueOrDefault ( f => f ( ) . GetType ( ) , typeof ( T ) ) ;
29
29
30
30
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 ( ) ;
32
33
33
34
var specs = from pt in specProps select pt . Specification ;
34
35
35
36
var optionSpecs = specs
36
37
. ThrowingValidate ( SpecificationGuards . Lookup )
37
- . OfType < OptionSpecification > ( ) ;
38
+ . OfType < OptionSpecification > ( )
39
+ . Memorize ( ) ;
38
40
39
41
Func < T > makeDefault = ( ) =>
40
42
typeof ( T ) . IsMutable ( )
@@ -45,18 +47,19 @@ public static ParserResult<T> Build<T>(
45
47
Func < IEnumerable < Error > , ParserResult < T > > notParsed =
46
48
errs => new NotParsed < T > ( makeDefault ( ) . GetType ( ) . ToTypeInfo ( ) , errs ) ;
47
49
50
+ var argumentsList = arguments . Memorize ( ) ;
48
51
Func < ParserResult < T > > buildUp = ( ) =>
49
52
{
50
- var tokenizerResult = tokenizer ( arguments , optionSpecs ) ;
53
+ var tokenizerResult = tokenizer ( argumentsList , optionSpecs ) ;
51
54
52
- var tokens = tokenizerResult . SucceededWith ( ) ;
55
+ var tokens = tokenizerResult . SucceededWith ( ) . Memorize ( ) ;
53
56
54
57
var partitions = TokenPartitioner . Partition (
55
58
tokens ,
56
59
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 ( ) ;
60
63
61
64
var optionSpecPropsResult =
62
65
OptionMapper . MapValues (
@@ -68,7 +71,7 @@ public static ParserResult<T> Build<T>(
68
71
var valueSpecPropsResult =
69
72
ValueMapper . MapValues (
70
73
( from pt in specProps where pt . Specification . IsValue ( ) orderby ( ( ValueSpecification ) pt . Specification ) . Index select pt ) ,
71
- valuesPartition ,
74
+ valuesPartition ,
72
75
( vals , type , isScalar ) => TypeConverter . ChangeType ( vals , type , isScalar , parsingCulture , ignoreValueCase ) ) ;
73
76
74
77
var missingValueErrors = from token in errorsPartition
@@ -78,7 +81,7 @@ public static ParserResult<T> Build<T>(
78
81
. FromOptionSpecification ( ) ) ;
79
82
80
83
var specPropsWithValue =
81
- optionSpecPropsResult . SucceededWith ( ) . Concat ( valueSpecPropsResult . SucceededWith ( ) ) ;
84
+ optionSpecPropsResult . SucceededWith ( ) . Concat ( valueSpecPropsResult . SucceededWith ( ) ) . Memorize ( ) ;
82
85
83
86
var setPropertyErrors = new List < Error > ( ) ;
84
87
@@ -130,11 +133,13 @@ join sp in specPropsWithValue on prms.Name.ToLower() equals sp.Property.Name.ToL
130
133
return allErrors . Except ( warnings ) . ToParserResult ( instance ) ;
131
134
} ;
132
135
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 ( ) ;
136
141
137
- var result = arguments . Any ( )
142
+ var result = argumentsList . Any ( )
138
143
? preprocessorErrors . Any ( )
139
144
? notParsed ( preprocessorErrors )
140
145
: buildUp ( )
0 commit comments