sklose / NCalc2

expression evaluator for .NET with built-in compiler
MIT License
166 stars 58 forks source link

Fix for exponential argument evaluation when using nulls #73

Closed david-brink-talogy closed 1 year ago

david-brink-talogy commented 1 year ago

It looks like there is an exponential increase in time complexity when evaluating arguments with a null value. For n terms, the first term is evaluated 2n-1 times, the second term is evaluated 2n-2 times, and so on.

This appears to be caused by the Visit(BinaryExpression) method which uses null as a sentinel value to indicate whether the left or right side has already been lazily evaluated. This change adds two booleans to track whether the halves have been visited.

This PR addresses #60, I've ensured all unit tests pass, and added additional tests to ensure nulls are evaluated as expected and within a reasonable time period.

sklose commented 1 year ago

@psiservices-dbrink , thank you for your contribution! 🚀