git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] merge: break out of all_strategy loop when strategy is found

From
RGRose via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 8, 2023, 18:39 UTC
Message-ID
<pull.1429.git.git.1673203153257.gitgitgadget@gmail.com>
From: Seija Kijin <doremylover123@gmail.com>

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>
---
    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-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1429/AtariDreams/exit-v1
Pull-Request: https://github.com/git/git/pull/1429
 builtin/merge.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 0f093f2a4f2..5ab0feb47b6 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -189,9 +189,12 @@ static struct strategy *get_strategy(const char *name)
 			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]) {
 					found = 1;
+					break;
+				}
 			if (!found)
 				add_cmdname(&not_strategies, ent->name, ent->len);
 		}

base-commit: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 4 in “merge: break out of all_strategy loop when strategy is found”
  1. merge: break out of all_strategy loop when strategy is foundRose via GitGitGadget, Jan 8, 2023
  2. Junio C HamanoJan 9, 2023
  3. merge: break out of all_strategy loop when strategy is foundRose via GitGitGadget, Jan 9, 2023
  4. Junio C HamanoJan 13, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.