Skip to content

Commit

Permalink
Replaced stream with for loop for slightly better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
r0goyal committed Nov 3, 2023
1 parent 65cdb02 commit 231be41
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,24 @@ public List<Boolean> evaluate(
final List<Evaluatable> evaluatables,
final JsonNode node) {
val logicEvaluator = new LogicEvaluator(new EvaluationContext(parseContext.parse(node), node, this));
return evaluatables.stream()
.map(evaluatable -> evaluatable.accept(logicEvaluator))
.collect(Collectors.toList());
List<Boolean> list = new ArrayList<>();
for (Evaluatable evaluatable : evaluatables) {
list.add(evaluatable.accept(logicEvaluator));
}
return list;
}

public OptionalInt evaluateFirst(
final List<Evaluatable> rules,
final JsonNode node) {
val logicEvaluator = new LogicEvaluator(new EvaluationContext(parseContext.parse(node), node, this));
return IntStream.range(0, rules.size())
.filter(index -> rules.get(index).accept(logicEvaluator))
.findFirst();
int bound = rules.size();
for (int index = 0; index < bound; index++) {
if (rules.get(index).accept(logicEvaluator)) {
return OptionalInt.of(index);
}
}
return OptionalInt.empty();
}

@Data
Expand Down

0 comments on commit 231be41

Please sign in to comment.