@@ -12,16 +12,13 @@ internal class ExpressionState
1212 public string WorkingText { get ; set ; } = string . Empty ;
1313 public readonly StringBuilder Buffer ;
1414
15- //private int _nextPreParsedCacheSlot = 0;
16- //private PreParsedCacheItem[] _preParsedCache = [];
17-
18- private int _nextParsedResultCacheSlot = 0 ;
19- private PreComputedCacheItem [ ] _preComputedCache = [ ] ;
20- private int _nextPreComputedCacheSlot = 0 ;
15+ private int _nextPositionStepCacheSlot = 0 ;
16+ private PlaceholderCacheItem [ ] _placeholderCache = [ ] ;
17+ private int _nextPlaceholderCacheSlot = 0 ;
2118 private int _operationCount = 0 ;
22- private ParsedResultCacheItem [ ] _parsedResultCache = [ ] ;
19+ private PositionStepCacheItem [ ] _positionStepCache = [ ] ;
2320 private readonly ExpressionOptions _options ;
24- private bool _isParsedResultCacheHydrated = false ;
21+ private bool _isPositionStepCacheHydrated = false ;
2522
2623 public ExpressionState ( Sanitized sanitized , ExpressionOptions options )
2724 {
@@ -30,14 +27,14 @@ public ExpressionState(Sanitized sanitized, ExpressionOptions options)
3027
3128 WorkingText = sanitized . Text ;
3229 _operationCount = sanitized . OperationCount ;
33- _nextPreComputedCacheSlot = sanitized . ConsumedPreComputedCacheSlots ;
34- _preComputedCache = new PreComputedCacheItem [ _operationCount + 10 ] ;
35- _parsedResultCache = new ParsedResultCacheItem [ _operationCount + 10 ] ;
36- _nextParsedResultCacheSlot = 0 ;
30+ _nextPlaceholderCacheSlot = sanitized . ConsumedPlaceholderCacheSlots ;
31+ _placeholderCache = new PlaceholderCacheItem [ _operationCount + 10 ] ;
32+ _positionStepCache = new PositionStepCacheItem [ _operationCount + 10 ] ;
33+ _nextPositionStepCacheSlot = 0 ;
3734
38- for ( int i = 0 ; i < sanitized . ConsumedPreComputedCacheSlots ; i ++ )
35+ for ( int i = 0 ; i < sanitized . ConsumedPlaceholderCacheSlots ; i ++ )
3936 {
40- _preComputedCache [ i ] = new PreComputedCacheItem ( )
37+ _placeholderCache [ i ] = new PlaceholderCacheItem ( )
4138 {
4239 ComputedValue = options . DefaultNullValue ,
4340 IsVariable = false ,
@@ -53,53 +50,53 @@ public ExpressionState(ExpressionOptions options, int preAllocation)
5350 _options = options ;
5451 }
5552
56- #region Parsed Result Cache Management.
53+ #region Position Step Cache Management.
5754
5855 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
59- public bool TryGetParsedResultCache ( [ NotNullWhen ( true ) ] out ParsedResultCacheItem value , out int slot )
56+ public bool TryGetPositionStepCache ( [ NotNullWhen ( true ) ] out PositionStepCacheItem value , out int slot )
6057 {
61- slot = _nextParsedResultCacheSlot ++ ;
58+ slot = _nextPositionStepCacheSlot ++ ;
6259
63- if ( slot < _nextParsedResultCacheSlot - 1 )
60+ if ( slot < _nextPositionStepCacheSlot - 1 )
6461 {
65- value = _parsedResultCache [ slot ] ;
62+ value = _positionStepCache [ slot ] ;
6663 return true ;
6764 }
6865 value = default ;
6966 return false ;
7067 }
7168
7269 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
73- public void StoreParsedResultCache ( int slot , ParsedResultCacheItem value )
70+ public void StorePositionStepCache ( int slot , PositionStepCacheItem value )
7471 {
75- if ( slot >= _parsedResultCache . Length ) //Resize the cache if needed.
72+ if ( slot >= _positionStepCache . Length ) //Resize the cache if needed.
7673 {
77- Array . Resize ( ref _parsedResultCache , ( _parsedResultCache . Length + 1 ) * 2 ) ;
74+ Array . Resize ( ref _positionStepCache , ( _positionStepCache . Length + 1 ) * 2 ) ;
7875 }
79- _parsedResultCache [ slot ] = value ;
76+ _positionStepCache [ slot ] = value ;
8077 }
8178
8279 #endregion
8380
84- #region Pre-Computed Cache Management.
81+ #region Placeholder Cache Management.
8582
86- public int ConsumeNextPreComputedCacheSlot ( out string cacheKey )
83+ public int ConsumeNextPlaceholderCacheSlot ( out string cacheKey )
8784 {
88- int cacheSlot = _nextPreComputedCacheSlot ++ ;
85+ int cacheSlot = _nextPlaceholderCacheSlot ++ ;
8986 cacheKey = $ "${ cacheSlot } $";
9087 return cacheSlot ;
9188 }
9289
93- public string StorePreComputedCacheItem ( double ? value , bool isVariable = false )
90+ public string StorePlaceholderCacheItem ( double ? value , bool isVariable = false )
9491 {
95- var cacheSlot = ConsumeNextPreComputedCacheSlot ( out var cacheKey ) ;
92+ var cacheSlot = ConsumeNextPlaceholderCacheSlot ( out var cacheKey ) ;
9693
97- if ( cacheSlot >= _preComputedCache . Length ) //Resize the cache if needed.
94+ if ( cacheSlot >= _placeholderCache . Length ) //Resize the cache if needed.
9895 {
99- Array . Resize ( ref _preComputedCache , ( _preComputedCache . Length + 1 ) * 2 ) ;
96+ Array . Resize ( ref _placeholderCache , ( _placeholderCache . Length + 1 ) * 2 ) ;
10097 }
10198
102- _preComputedCache [ cacheSlot ] = new PreComputedCacheItem ( )
99+ _placeholderCache [ cacheSlot ] = new PlaceholderCacheItem ( )
103100 {
104101 IsVariable = isVariable ,
105102 ComputedValue = value
@@ -108,50 +105,52 @@ public string StorePreComputedCacheItem(double? value, bool isVariable = false)
108105 return cacheKey ;
109106 }
110107
111- public PreComputedCacheItem GetPreComputedCacheItem ( ReadOnlySpan < char > span )
108+ public PlaceholderCacheItem GetPlaceholderCacheItem ( ReadOnlySpan < char > span )
112109 {
113110 switch ( span . Length )
114111 {
115112 case 1 :
116- return _preComputedCache [ span [ 0 ] - '0' ] ;
113+ return _placeholderCache [ span [ 0 ] - '0' ] ;
117114 default :
118115 int index = 0 ;
119116 for ( int i = 0 ; i < span . Length ; i ++ )
120117 index = index * 10 + ( span [ i ] - '0' ) ;
121- return _preComputedCache [ index ] ;
118+ return _placeholderCache [ index ] ;
122119 }
123120 }
124121
125122 #endregion
126123
124+ /*
127125 public void HydrateTemplateParsedCache(int expressionHash)
128126 {
129- if ( ! _isParsedResultCacheHydrated )
127+ if (!_isPositionStepCacheHydrated )
130128 {
131129 lock (this)
132130 {
133- if ( ! _isParsedResultCacheHydrated )
131+ if (!_isPositionStepCacheHydrated )
134132 {
135133 if (Utility.PersistentCaches.TryGetValue(expressionHash, out CachedState? entry) && entry != null)
136134 {
137- entry . State . HydrateParsedResultCache ( _parsedResultCache ) ;
135+ entry.State.HydratePositionStepCache(_positionStepCache );
138136 }
139- _isParsedResultCacheHydrated = true ;
137+ _isPositionStepCacheHydrated = true;
140138 }
141139 }
142140 }
143141 }
144142
145- private void HydrateParsedResultCache ( ParsedResultCacheItem [ ] populatedCache )
143+ private void HydratePositionStepCache(PositionStepCacheItem [] populatedCache)
146144 {
147- Interlocked . Exchange ( ref _parsedResultCache , populatedCache ) ;
145+ Interlocked.Exchange(ref _positionStepCache , populatedCache);
148146 }
147+ */
149148
150149 public void Reset ( Sanitized sanitized )
151150 {
152151 WorkingText = sanitized . Text ;
153- _nextPreComputedCacheSlot = sanitized . ConsumedPreComputedCacheSlots ;
154- _nextParsedResultCacheSlot = 0 ;
152+ _nextPlaceholderCacheSlot = sanitized . ConsumedPlaceholderCacheSlots ;
153+ _nextPositionStepCacheSlot = 0 ;
155154 }
156155
157156 public ExpressionState Clone ( )
@@ -160,15 +159,15 @@ public ExpressionState Clone()
160159 {
161160 WorkingText = WorkingText ,
162161 _operationCount = _operationCount ,
163- _nextPreComputedCacheSlot = _nextPreComputedCacheSlot ,
164- _preComputedCache = new PreComputedCacheItem [ _preComputedCache . Length ] ,
165- _parsedResultCache = new ParsedResultCacheItem [ _parsedResultCache . Length ] ,
166- _nextParsedResultCacheSlot = 0 ,
167- _isParsedResultCacheHydrated = _isParsedResultCacheHydrated
162+ _nextPlaceholderCacheSlot = _nextPlaceholderCacheSlot ,
163+ _placeholderCache = new PlaceholderCacheItem [ _placeholderCache . Length ] ,
164+ _positionStepCache = new PositionStepCacheItem [ _positionStepCache . Length ] ,
165+ _nextPositionStepCacheSlot = 0 ,
166+ _isPositionStepCacheHydrated = _isPositionStepCacheHydrated
168167 } ;
169168
170- Array . Copy ( _preComputedCache , clone . _preComputedCache , _preComputedCache . Length ) ; //Copy any pre-computed NULLs.
171- Array . Copy ( _parsedResultCache , clone . _parsedResultCache , _parsedResultCache . Length ) ;
169+ Array . Copy ( _placeholderCache , clone . _placeholderCache , _placeholderCache . Length ) ; //Copy any pre-computed NULLs.
170+ Array . Copy ( _positionStepCache , clone . _positionStepCache , _positionStepCache . Length ) ;
172171
173172 return clone ;
174173 }
@@ -180,8 +179,8 @@ public void ApplyParameters(Sanitized sanitized, Dictionary<string, double?> def
180179 {
181180 if ( definedParameters . TryGetValue ( variable , out var value ) )
182181 {
183- var cacheSlot = ConsumeNextPreComputedCacheSlot ( out var cacheKey ) ;
184- _preComputedCache [ cacheSlot ] = new PreComputedCacheItem ( )
182+ var cacheSlot = ConsumeNextPlaceholderCacheSlot ( out var cacheKey ) ;
183+ _placeholderCache [ cacheSlot ] = new PlaceholderCacheItem ( )
185184 {
186185 ComputedValue = value ?? _options . DefaultNullValue ,
187186 IsVariable = true
0 commit comments