From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756657AbdGXXnX (ORCPT ); Mon, 24 Jul 2017 19:43:23 -0400 Received: from mga06.intel.com ([134.134.136.31]:20901 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756129AbdGXXk2 (ORCPT ); Mon, 24 Jul 2017 19:40:28 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,409,1496127600"; d="scan'208";a="115133813" From: Andi Kleen To: acme@kernel.org Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH v1 09/15] perf, tools: Dedup events in expression parsing Date: Mon, 24 Jul 2017 16:40:09 -0700 Message-Id: <20170724234015.5165-10-andi@firstfloor.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170724234015.5165-1-andi@firstfloor.org> References: <20170724234015.5165-1-andi@firstfloor.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen Avoid adding redundant events while parsing an expression. When we add an "other" event check first if it already exists. Signed-off-by: Andi Kleen --- tools/perf/util/expr.y | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y index 5753c4f21534..f54928f00893 100644 --- a/tools/perf/util/expr.y +++ b/tools/perf/util/expr.y @@ -181,6 +181,19 @@ void expr__ctx_init(struct parse_ctx *ctx) ctx->num_ids = 0; } +static bool already_seen(const char *val, const char *one, const char **other, + int num_other) +{ + int i; + + if (one && !strcasecmp(one, val)) + return false; + for (i = 0; i < num_other; i++) + if (!strcasecmp(other[i], val)) + return true; + return false; +} + int expr__find_other(const char *p, const char *one, const char ***other, int *num_otherp) { @@ -200,7 +213,7 @@ int expr__find_other(const char *p, const char *one, const char ***other, err = 0; break; } - if (tok == ID && (!one || strcasecmp(one, val.id))) { + if (tok == ID && !already_seen(val.id, one, *other, num_other)) { if (num_other >= EXPR_MAX_OTHER - 1) { pr_debug("Too many extra events in %s\n", orig); break; -- 2.9.4