Releases: boxbeam/Crunch
Shallow cloning for CompiledExpression
CompiledExpression
effectively just wraps a Value
and handles caching the variableValues
array to minimize allocations. This makes it thread-unsafe, but in the previous update, the entire expression tree is now decoupled from the CompiledExpression
since variable values are passed through an array function parameter rather than having Variable
objects store a reference to the expression they belong to. This means that clone()
can now reuse the same Value
instance, effectively only cloning the wrapper that caches the array.
The benefit of this is that it is now O(1)
to clone a CompiledExpression, whereas before it would take longer the larger the expression is, and require far more allocations. It should be virtually free to multithread with Crunch now.
Make variables no longer reference the expression they belong to
Fixes a bug affecting cloned expressions that have variables, wherein the variables would still refer to the old expression
Allow ExpressionEnv methods to be used builder-style
Also includes some refactoring courtesy of @IllusionTheDev
2.0 - Parser rewrite
A bug was reported by Discord user ErikH which I couldn't find the cause of, due to the old parser code being practically unreadable. I've rewritten the parser entirely, and the code is now much cleaner, along with several improvements and one breaking change.
Breaking changes
Implicit multiplication is no longer supported
Changes
- Parser performance improved by 15%
- Fixed bug causing expression
max( 0.0, (378044 * 100 / 100.0 - 294964) * 1.0 ) - 0.0
to not be parsable - Improved error messages display where in the input an error happened by visually pointing it out:
- Updated benchmarks written with jmh now available at https://github.com/Redempt/CrunchBenchmark, results in readme
- Repeating unary operators no longer breaks the parser (
!!true
,--1
)
Fix inlining of rand function
The rand operator was able to be inlined if it was used on a constant, resulting in the same value being produced every time the expression is evaluated. This no longer happens.
Add != operator, adjust priority of boolean operators
- Should improve clarity of boolean expressions and make them easier to write
Add TokenType for lazy variables
Fixes issue which would cause lazy variables to be collapsed into literal values
Add support for lazy variables
- Lazy variables do not need to be passed with the other variable values
- Defined with a name and lambda, and evaluated lazily when the expression is run
- Good for when you have values that might be used, but might not and are computationally expensive to recalculate each step