Skip to content

Commit 5571927

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing/filter: Optimize short ciruit check
The test if we should break out early for OR and AND operations can be optimized by comparing the current result with (pred->op == OP_OR) That is if the result is true and the op is an OP_OR, or if the result is false and the op is not an OP_OR (thus an OP_AND) we can break out early in either case. Otherwise we continue processing. Cc: Tom Zanussi <tzanussi@gmail.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 61e9dea commit 5571927

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

kernel/trace/trace_events_filter.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,15 @@ int filter_match_preds(struct event_filter *filter, void *rec)
426426
pred->parent, &move);
427427
continue;
428428
case MOVE_UP_FROM_LEFT:
429-
/* Check for short circuits */
430-
if ((match && pred->op == OP_OR) ||
431-
(!match && pred->op == OP_AND)) {
429+
/*
430+
* Check for short circuits.
431+
*
432+
* Optimization: !!match == (pred->op == OP_OR)
433+
* is the same as:
434+
* if ((match && pred->op == OP_OR) ||
435+
* (!match && pred->op == OP_AND))
436+
*/
437+
if (!!match == (pred->op == OP_OR)) {
432438
if (pred == root)
433439
break;
434440
pred = get_pred_parent(pred, preds,

0 commit comments

Comments
 (0)