[PATCH v9 03/13] perf expr: Remove unused headers and inline d_ratio

Ian Rogers
2021-09-23T07:46:57Z

No functional change. Inlining d_ratio makes it easier to special case
for constants in a later patch.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/expr.y | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
index 41c9cd4efadd..e6005450feae 100644
--- a/tools/perf/util/expr.y
+++ b/tools/perf/util/expr.y
@@ -2,23 +2,10 @@
%{
#define YYDEBUG 1
#include <math.h>
-#include <stdio.h>
-#include "util.h"
#include "util/debug.h"
-#include <stdlib.h> // strtod()
+#include "smt.h"
#define IN_EXPR_Y 1
#include "expr.h"
-#include "smt.h"
-#include <string.h>
-
-static double d_ratio(double val0, double val1)
-{
- if (val1 == 0) {
- return 0;
- }
- return val0 / val1;
-}
-
%}

%define api.pure full
@@ -120,7 +107,12 @@ expr: NUMBER
| MIN '(' expr ',' expr ')' { $$ = $3 < $5 ? $3 : $5; }
| MAX '(' expr ',' expr ')' { $$ = $3 > $5 ? $3 : $5; }
| SMT_ON { $$ = smt_on() > 0; }
- | D_RATIO '(' expr ',' expr ')' { $$ = d_ratio($3,$5); }
+ | D_RATIO '(' expr ',' expr ')' { if ($5 == 0) {
+ $$ = 0;
+ } else {
+ $$ = $3 / $5;
+ }
+ }
;

%%
--
2.33.0.464.g1972c5931b-goog