Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp686731rwb; Sat, 3 Sep 2022 00:16:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR57e0Q8WJipvJmEHnErQ9mkk/wrP9fbY+m9gkrgtvr+CFISOqUjrwORTePOFNtZ4+8neGXd X-Received: by 2002:a05:6a00:a1d:b0:536:90d3:1930 with SMTP id p29-20020a056a000a1d00b0053690d31930mr39397911pfh.25.1662189381824; Sat, 03 Sep 2022 00:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662189381; cv=none; d=google.com; s=arc-20160816; b=eQi2OIsDjSSZKt8tKfxuWiBpwA0D7PzClGK0YGJgTCgwIa2AXTO9euUoyx+HV5DEDK 1Tyn/kNoEtJWgGwDC+wO08wS4nHA47hEYATOsUFfcLaR/mBlNqa6KGBR+z1huhZpbD/3 8h60ttNXj9SRrSLS+ms25pIdUubQy6AK95qNGu4HFH4KPtHAPUTK9MBllYMyN5NLxGK5 vB+BPis2OXUgAhwdBXVNJuRv619/TjPlD5splSfKF+dRcFqNd83CFZzikpuXP3KTinat 0J1bFKmpmD89GMi0b9s//X5Jkr6TAb/wR5gtBELUFCB4zHXeL717UdhpRCfZusnhytTN EzTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=YCOBuWerM3rD9+F6t9c7in4WCD8PyycOYzEkI8p4c4I=; b=q+wsfEGot36beRlBsWd4yL4q7U4Iv1LGI7/MSGYStmGK9FA5y8Vd0FWDsG9Z+fA6J7 5ShhDEFDHJoZnJ/azqF2AYNS28ywhbDH6zGsoz36KS9OF8NTRP+eZ9SxoP5QYt7g4ETz SE4UEb+ZvhbVzLiGvaXGS6PYimiO7i3X1XGBjc+nRKz09loVRaInVs/Fdt1JCttM6Fb0 /oyhcVVJTBfTaVJtCJQp7piTG8H0wFKM4/rTGCMwXmSk+ifSoge0okjRsh24kNZ8uTSC JQgnGhE3Sa//6Lb3usq8nb4xJC+Qa2NDpxJfoQbSMNLP3ghLBbvXHlLtl8MnDfdV7fnM 6Wug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v20-20020a634814000000b0041db9f07695si3878637pga.753.2022.09.03.00.16.09; Sat, 03 Sep 2022 00:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232762AbiICGvK (ORCPT + 99 others); Sat, 3 Sep 2022 02:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbiICGvC (ORCPT ); Sat, 3 Sep 2022 02:51:02 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FB22481C0; Fri, 2 Sep 2022 23:51:01 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MKQKv12F6zWfBL; Sat, 3 Sep 2022 14:46:27 +0800 (CST) Received: from kwepemm600008.china.huawei.com (7.193.23.88) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 3 Sep 2022 14:50:53 +0800 Received: from huawei.com (10.175.100.227) by kwepemm600008.china.huawei.com (7.193.23.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 3 Sep 2022 14:50:52 +0800 From: Shang XiaoJing To: , , , , , , , , CC: Subject: [PATCH 1/3] perf clean: Add same_cmd_with_prefix helper Date: Sat, 3 Sep 2022 15:25:40 +0800 Message-ID: <20220903072542.27678-2-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220903072542.27678-1-shangxiaojing@huawei.com> References: <20220903072542.27678-1-shangxiaojing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.100.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600008.china.huawei.com (7.193.23.88) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wrap repeated code in helper function same_cmd_with_prefix for more clearly. Signed-off-by: Shang XiaoJing --- tools/perf/perf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index c21b3973641a..7af135dea1cd 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -99,10 +99,16 @@ struct pager_config { int val; }; +static bool same_cmd_with_prefix(const char *var, struct pager_config *c, + const char *header) +{ + return (strstarts(var, header) && !strcmp(var + strlen(header), c->cmd)); +} + static int pager_command_config(const char *var, const char *value, void *data) { struct pager_config *c = data; - if (strstarts(var, "pager.") && !strcmp(var + 6, c->cmd)) + if (same_cmd_with_prefix(var, c, "pager.")) c->val = perf_config_bool(var, value); return 0; } @@ -121,9 +127,9 @@ static int check_pager_config(const char *cmd) static int browser_command_config(const char *var, const char *value, void *data) { struct pager_config *c = data; - if (strstarts(var, "tui.") && !strcmp(var + 4, c->cmd)) + if (same_cmd_with_prefix(var, c, "tui.")) c->val = perf_config_bool(var, value); - if (strstarts(var, "gtk.") && !strcmp(var + 4, c->cmd)) + if (same_cmd_with_prefix(var, c, "gtk.")) c->val = perf_config_bool(var, value) ? 2 : 0; return 0; } -- 2.17.1