Skip to content

Commit c2c19fb

Browse files
authored
Merge pull request #728 from sys27/optimization
Optimization
2 parents 1125a32 + 60da267 commit c2c19fb

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

xFunc.Maths/Expressions/Matrices/VectorValue.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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>

xFunc.Maths/Tokenization/Lexer.KeywordToken.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff 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

xFunc.Maths/Tokenization/Lexer.StringToken.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff 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];

0 commit comments

Comments
 (0)