Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improving evaluating performance #34

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ abstract class Evaluator(
fun evaluate(expression: Expression, inputData: Any): Boolean {
return usingFailureWrapper(expression.onFailure) {
call(inputData) {
val processIsTrue = expression.takeIf { v -> v.parseable() }?.processExpression(it) ?: true
val processNoneMatch = expression.noneMatch?.processNoneMatch(it) ?: true
val processAnyMatch = expression.anyMatch?.processAnyMatch(it) ?: true
val processAllMatch = expression.allMatch?.processAllMatch(it) ?: true

processIsTrue && processNoneMatch && processAnyMatch && processAllMatch
expression.takeIf { v -> v.parseable() }?.processExpression(it) ?: true &&
expression.noneMatch?.processNoneMatch(it) ?: true &&
expression.anyMatch?.processAnyMatch(it) ?: true &&
expression.allMatch?.processAllMatch(it) ?: true
}
}
}
Expand Down Expand Up @@ -64,38 +62,32 @@ abstract class Evaluator(
private fun List<Expression>.processNoneMatch(context: EvalContext): Boolean {
return this.none {
usingFailureWrapper(it.onFailure) {
val isTrue = it.takeIf { v -> v.parseable() }?.processExpression(context) == true
val noneMatch = it.noneMatch?.processNoneMatch(context) == false
val anyMatch = it.anyMatch?.processAnyMatch(context) == true
val allMatch = it.allMatch?.processAllMatch(context) == true

isTrue || noneMatch || anyMatch || allMatch
it.takeIf { v -> v.parseable() }?.processExpression(context) == true ||
it.noneMatch?.processNoneMatch(context) == false ||
it.anyMatch?.processAnyMatch(context) == true ||
it.allMatch?.processAllMatch(context) == true
}
}
}

private fun List<Expression>.processAnyMatch(context: EvalContext): Boolean {
return this.any {
usingFailureWrapper(it.onFailure) {
val isTrue = it.takeIf { v -> v.parseable() }?.processExpression(context) == true
val anyMatch = it.anyMatch?.processAnyMatch(context) ?: false
val noneMatch = it.noneMatch?.processNoneMatch(context) == true
val allMatch = it.allMatch?.processAllMatch(context) == true

isTrue || anyMatch || noneMatch || allMatch
it.takeIf { v -> v.parseable() }?.processExpression(context) == true ||
it.anyMatch?.processAnyMatch(context) ?: false ||
it.noneMatch?.processNoneMatch(context) == true ||
it.allMatch?.processAllMatch(context) == true
}
}
}

private fun List<Expression>.processAllMatch(context: EvalContext): Boolean {
return this.none {
usingFailureWrapper(it.onFailure) {
val isTrue = it.takeIf { v -> v.parseable() }?.processExpression(context) == false
val anyMatch = it.anyMatch?.processAnyMatch(context) == false
val noneMatch = it.noneMatch?.processNoneMatch(context) == false
val allMatch = it.allMatch?.processAllMatch(context) == false

isTrue || anyMatch || noneMatch || allMatch
it.takeIf { v -> v.parseable() }?.processExpression(context) == false ||
it.anyMatch?.processAnyMatch(context) == false ||
it.noneMatch?.processNoneMatch(context) == false ||
it.allMatch?.processAllMatch(context) == false
}
}
}
Expand Down
Loading