File tree Expand file tree Collapse file tree 3 files changed +11
-21
lines changed Expand file tree Collapse file tree 3 files changed +11
-21
lines changed Original file line number Diff line number Diff line change @@ -174,12 +174,12 @@ public NumberValue Average()
174174 /// <returns>The sum of the values in the vector.</returns>
175175 public NumberValue Sum ( )
176176 {
177- var sum = NumberValue . Zero ;
177+ var sum = 0.0 ;
178178
179- for ( var i = 0 ; i < Size ; i ++ )
180- sum += array [ i ] ;
179+ for ( var i = 0 ; i < array . Length ; i ++ )
180+ sum += array [ i ] . Number ;
181181
182- return sum ;
182+ return new NumberValue ( sum ) ;
183183 }
184184
185185 /// <summary>
Original file line number Diff line number Diff line change @@ -21,9 +21,11 @@ private bool CreateKeywordToken()
2121
2222 var keyword = function [ ..endIndex ] ;
2323
24- var lowerKeyword = keyword . Length <= 1024
25- ? stackalloc char [ keyword . Length ]
26- : new char [ keyword . Length ] ;
24+ // keyword shouldn't be bigger than the biggest valid keyword
25+ if ( keyword . Length > "unassign" . Length )
26+ return false ;
27+
28+ Span < char > lowerKeyword = stackalloc char [ keyword . Length ] ;
2729
2830 keyword . ToLowerInvariant ( lowerKeyword ) ;
2931
Original file line number Diff line number Diff line change @@ -13,20 +13,8 @@ private bool CreateStringToken(char quote)
1313 if ( function [ 0 ] != quote )
1414 return false ;
1515
16- var endIndex = 1 ;
17- var foundClosingQuote = false ;
18- while ( endIndex < function . Length )
19- {
20- if ( function [ endIndex ] == quote )
21- {
22- foundClosingQuote = true ;
23- break ;
24- }
25-
26- endIndex ++ ;
27- }
28-
29- if ( ! foundClosingQuote )
16+ var endIndex = function [ 1 ..] . IndexOf ( quote ) + 1 ;
17+ if ( endIndex == 0 )
3018 throw new TokenizeException ( Resource . StringTokenizeException ) ;
3119
3220 var stringValue = function [ 1 ..endIndex ] ;
You can’t perform that action at this time.
0 commit comments