From: "Rose via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Rose <83477269+AtariDreams@users.noreply.github.com>,
Seija Kijin <doremylover123@gmail.com>
Subject: [PATCH v2] merge: break out of all_strategy loop when strategy is found
Date: Mon, 09 Jan 2023 17:34:28 +0000 [thread overview]
Message-ID: <pull.1429.v2.git.git.1673285669004.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1429.git.git.1673203153257.gitgitgadget@gmail.com>
From: Seija Kijin <doremylover123@gmail.com>
strncmp does not modify any of the memory.
Once we find a match, there is no point
in trying to find the second match
in the inner loop.
Break out of the loop once we
find the first match.
Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
merge: break out of all_strategy loop when strategy is found
strncmp does not modify any of the memory, so looping through all
elements is a waste of resources.
Signed-off-by: Seija Kijin doremylover123@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1429%2FAtariDreams%2Fexit-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1429/AtariDreams/exit-v2
Pull-Request: https://github.com/git/git/pull/1429
Range-diff vs v1:
1: 82c1d021b2c ! 1: d93d4aff780 merge: break out of all_strategy loop when strategy is found
@@ Metadata
## Commit message ##
merge: break out of all_strategy loop when strategy is found
- strncmp does not modify any of the memory,
- so looping through all elements is a waste of resources.
+ strncmp does not modify any of the memory.
+ Once we find a match, there is no point
+ in trying to find the second match
+ in the inner loop.
+
+ Break out of the loop once we
+ find the first match.
Signed-off-by: Seija Kijin <doremylover123@gmail.com>
## builtin/merge.c ##
@@ builtin/merge.c: static struct strategy *get_strategy(const char *name)
+ for (i = 0; i < main_cmds.cnt; i++) {
int j, found = 0;
struct cmdname *ent = main_cmds.names[i];
- for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
-- if (!strncmp(ent->name, all_strategy[j].name, ent->len)
-- && !all_strategy[j].name[ent->len])
-+ if (!strncmp(ent->name, all_strategy[j].name,
-+ ent->len) &&
-+ !all_strategy[j].name[ent->len]) {
+- for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
++ for (j = 0; !found && j < ARRAY_SIZE(all_strategy); j++)
+ if (!strncmp(ent->name, all_strategy[j].name, ent->len)
+ && !all_strategy[j].name[ent->len])
found = 1;
-+ break;
-+ }
- if (!found)
- add_cmdname(¬_strategies, ent->name, ent->len);
- }
builtin/merge.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 0f093f2a4f2..74de2ebd2b3 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -188,7 +188,7 @@ static struct strategy *get_strategy(const char *name)
for (i = 0; i < main_cmds.cnt; i++) {
int j, found = 0;
struct cmdname *ent = main_cmds.names[i];
- for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
+ for (j = 0; !found && j < ARRAY_SIZE(all_strategy); j++)
if (!strncmp(ent->name, all_strategy[j].name, ent->len)
&& !all_strategy[j].name[ent->len])
found = 1;
base-commit: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1
--
gitgitgadget
next prev parent reply other threads:[~2023-01-09 17:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-08 18:39 [PATCH] merge: break out of all_strategy loop when strategy is found Rose via GitGitGadget
2023-01-09 5:14 ` Junio C Hamano
2023-01-09 17:34 ` Rose via GitGitGadget [this message]
2023-01-13 18:24 ` [PATCH v2] " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1429.v2.git.git.1673285669004.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=83477269+AtariDreams@users.noreply.github.com \
--cc=doremylover123@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).