Skip to content

Commit

Permalink
Merge pull request #728 from sys27/optimization
Browse files Browse the repository at this point in the history
Optimization
  • Loading branch information
sys27 authored Sep 14, 2023
2 parents 1125a32 + 60da267 commit c2c19fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
8 changes: 4 additions & 4 deletions xFunc.Maths/Expressions/Matrices/VectorValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ public NumberValue Average()
/// <returns>The sum of the values in the vector.</returns>
public NumberValue Sum()
{
var sum = NumberValue.Zero;
var sum = 0.0;

for (var i = 0; i < Size; i++)
sum += array[i];
for (var i = 0; i < array.Length; i++)
sum += array[i].Number;

return sum;
return new NumberValue(sum);
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions xFunc.Maths/Tokenization/Lexer.KeywordToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ private bool CreateKeywordToken()

var keyword = function[..endIndex];

var lowerKeyword = keyword.Length <= 1024
? stackalloc char[keyword.Length]
: new char[keyword.Length];
// keyword shouldn't be bigger than the biggest valid keyword
if (keyword.Length > "unassign".Length)
return false;

Span<char> lowerKeyword = stackalloc char[keyword.Length];

keyword.ToLowerInvariant(lowerKeyword);

Expand Down
16 changes: 2 additions & 14 deletions xFunc.Maths/Tokenization/Lexer.StringToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,8 @@ private bool CreateStringToken(char quote)
if (function[0] != quote)
return false;

var endIndex = 1;
var foundClosingQuote = false;
while (endIndex < function.Length)
{
if (function[endIndex] == quote)
{
foundClosingQuote = true;
break;
}

endIndex++;
}

if (!foundClosingQuote)
var endIndex = function[1..].IndexOf(quote) + 1;
if (endIndex == 0)
throw new TokenizeException(Resource.StringTokenizeException);

var stringValue = function[1..endIndex];
Expand Down

0 comments on commit c2c19fb

Please sign in to comment.