-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce state machines in binary expressions (#311)
- Loading branch information
Showing
17 changed files
with
188 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,16 @@ | ||
using System.Threading.Tasks; | ||
using Fluid.Values; | ||
using Fluid.Values; | ||
|
||
namespace Fluid.Ast.BinaryExpressions | ||
{ | ||
public class AndBinaryExpression : BinaryExpression | ||
public sealed class AndBinaryExpression : BinaryExpression | ||
{ | ||
public AndBinaryExpression(Expression left, Expression right) : base(left, right) | ||
{ | ||
} | ||
|
||
public override ValueTask<FluidValue> EvaluateAsync(TemplateContext context) | ||
internal override FluidValue Evaluate(FluidValue leftValue, FluidValue rightValue) | ||
{ | ||
static async ValueTask<FluidValue> Awaited(ValueTask<FluidValue> leftTask, ValueTask<FluidValue> rightTask) | ||
{ | ||
var leftValue = await leftTask; | ||
var rightValue = await rightTask; | ||
|
||
return BooleanValue.Create(leftValue.ToBooleanValue() && rightValue.ToBooleanValue()); | ||
} | ||
|
||
var leftTask = Left.EvaluateAsync(context); | ||
var rightTask = Right.EvaluateAsync(context); | ||
|
||
if (leftTask.IsCompletedSuccessfully && rightTask.IsCompletedSuccessfully) | ||
{ | ||
return BooleanValue.Create(leftTask.Result.ToBooleanValue() && rightTask.Result.ToBooleanValue()); | ||
} | ||
|
||
return Awaited(leftTask, rightTask); | ||
return BooleanValue.Create(leftValue.ToBooleanValue() && rightValue.ToBooleanValue()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
using System.Threading.Tasks; | ||
using Fluid.Values; | ||
using Fluid.Values; | ||
|
||
namespace Fluid.Ast.BinaryExpressions | ||
{ | ||
public class ContainsBinaryExpression : BinaryExpression | ||
public sealed class ContainsBinaryExpression : BinaryExpression | ||
{ | ||
public ContainsBinaryExpression(Expression left, Expression right) : base(left, right) | ||
{ | ||
} | ||
|
||
public override async ValueTask<FluidValue> EvaluateAsync(TemplateContext context) | ||
internal override FluidValue Evaluate(FluidValue leftValue, FluidValue rightValue) | ||
{ | ||
var leftValue = await Left.EvaluateAsync(context); | ||
var rightValue = await Right.EvaluateAsync(context); | ||
|
||
return leftValue.Contains(rightValue) | ||
? BooleanValue.True | ||
: BooleanValue.False; | ||
? BooleanValue.True | ||
: BooleanValue.False; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
using System.Threading.Tasks; | ||
using Fluid.Values; | ||
using Fluid.Values; | ||
|
||
namespace Fluid.Ast.BinaryExpressions | ||
{ | ||
public class EqualBinaryExpression : BinaryExpression | ||
public sealed class EqualBinaryExpression : BinaryExpression | ||
{ | ||
public EqualBinaryExpression(Expression left, Expression right) : base(left, right) | ||
{ | ||
} | ||
|
||
public override async ValueTask<FluidValue> EvaluateAsync(TemplateContext context) | ||
internal override FluidValue Evaluate(FluidValue leftValue, FluidValue rightValue) | ||
{ | ||
var leftValue = await Left.EvaluateAsync(context); | ||
var rightValue = await Right.EvaluateAsync(context); | ||
|
||
if (leftValue.Equals(rightValue)) | ||
{ | ||
return BooleanValue.True; | ||
} | ||
|
||
return BooleanValue.False; | ||
return leftValue.Equals(rightValue) | ||
? BooleanValue.True | ||
: BooleanValue.False; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.