From patchwork Sat Feb 24 21:29:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13570639 Received: from mout.web.de (mout.web.de [212.227.15.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82528487BE for ; Sat, 24 Feb 2024 21:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708810287; cv=none; b=qLoZ7FBYA+TZOv+W5QLmCarFXuwhTEnLZztvq6XGA+cbiowIYtzMx/d3zGK8m81osdNSOC1zO54RDt09qbMEnsBiyc33RjAUqFcogtMkRS3ddQuGqNcaln3SuquINCHPrBKLnQq6+mNR7xWOSaDcCSLzF82ec5MhZgPZ5BNZOQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708810287; c=relaxed/simple; bh=Nds33saJzzY1UNPZ69vw35wHgwdWlaG0fInbPvL1h8I=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ABryRMYt0XaAMzTcKGjuJof826u9/FPZzsywU8CzhQm+AZgu9ISWmaHbved/Mzp1ObsW60H7MS7IOn4OjiMLrNyKEvYwZxA0dofqUEUNnv4V5VtA0dyMAUD3EH4kYiL6Xlj1UHdt6U+3e4K564N6k8JtPWXma5NUysjBZlLEw3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=voi0QnT7; arc=none smtp.client-ip=212.227.15.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="voi0QnT7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1708810277; x=1709415077; i=l.s.r@web.de; bh=Nds33saJzzY1UNPZ69vw35wHgwdWlaG0fInbPvL1h8I=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=voi0QnT75DIv6uiNmZFPidV945RUUE1n8oVgMZ/oGHC2mwvZs9OjumH7ibKYM/Y7 dp8Hvm4Z++E1QIGRrsxDg9qwL4HGXqmxOrr39RBNLDhVZG8kaiLa/ljDKelvCcQoP tZVJfnqUYRlJgqFmWofCym2kG4MIayHDgdcFmImjfavLuKMi++b7huLHSCosO2SVb LnUeskg3LoAfiLzx5Uw0yBrXnQdnkPFQ44B6GOm3hSX4sH8ilyYO4y/LhAwjJmitI YPk3iBFxtrmbAQkhZc1RDMtLIYOm6JCyWDNRv1iwnMAt36hOn3W8glEoROmPr5xrq O0i9Qb8dio6r7FGkWA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from Mini-von-Rene.fritz.box ([79.203.19.211]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MUCut-1rUooY1ITT-00RKFN for ; Sat, 24 Feb 2024 22:31:17 +0100 From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: git@vger.kernel.org Subject: [PATCH 2/6] parse-options: set arg of abbreviated option lazily Date: Sat, 24 Feb 2024 22:29:49 +0100 Message-ID: <20240224212953.44026-3-l.s.r@web.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224212953.44026-1-l.s.r@web.de> References: <20240224212953.44026-1-l.s.r@web.de> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Prov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omZQq/A7RKIgXJDB7CTlDbHUJrzKpKLJGhIkTWXlDM9RiduO jdh6eenAUivb2GZat3T2cgiIJ0oh+7ixDlbeR85dk5lcc= Postpone setting the opt pointer until we're about to call get_value(), which uses it. There's no point in setting it eagerly for every abbreviated candidate option, which may turn out to be ambiguous. Removing this assignment from the loop doesn't noticeably improve the performance, but allows further simplification. --- parse-options.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.44.0 diff --git a/parse-options.c b/parse-options.c index e4ce33ea48..056c6b30e9 100644 --- a/parse-options.c +++ b/parse-options.c @@ -391,8 +391,6 @@ static enum parse_opt_result parse_long_opt( ambiguous_option = abbrev_option; ambiguous_flags = abbrev_flags; } - if (*arg_end) - p->opt = arg_end + 1; abbrev_option = options; abbrev_flags = flags ^ opt_flags; continue; @@ -441,8 +439,11 @@ static enum parse_opt_result parse_long_opt( abbrev_option->long_name); return PARSE_OPT_HELP; } - if (abbrev_option) + if (abbrev_option) { + if (*arg_end) + p->opt = arg_end + 1; return get_value(p, abbrev_option, abbrev_flags); + } return PARSE_OPT_UNKNOWN; }