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

[PATCH 2/3] mailmap: use higher level string list functions

From
Stefan Beller <sbeller@google.com>
Date
Nov 24, 2014, 21:22 UTC
Message-ID
<1416864124-15231-2-git-send-email-sbeller@google.com>
In-Reply-To
<1416864124-15231-1-git-send-email-sbeller@google.com>

No functional changes intended. This commit makes user of higher level and better documented functions of the string list API, so the code is more understandable.

Note that also the required computational amount should not change in principal as we need to look up the item no matter if it is already part of the list or not. Once looked up, insertion comes for free.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 mailmap.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/mailmap.c b/mailmap.c
index 81890a6..f0df350 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -78,15 +78,10 @@ static void add_mapping(struct string_list *map,
 		new_email = NULL;
 	}
 
-	if ((index = string_list_find_insert_index(map, old_email, 1)) < 0) {
-		/* mailmap entry exists, invert index value */
-		index = -1 - index;
-		me = (struct mailmap_entry *)map->items[index].util;
+	struct string_list_item *item = string_list_insert(map, old_email);
+	if (item->util) {
+		me = (struct mailmap_entry *)item->util;
 	} else {
-		/* create mailmap entry */
-		struct string_list_item *item;
-
-		item = string_list_insert_at_index(map, index, old_email);
 		me = xcalloc(1, sizeof(struct mailmap_entry));
 		me->namemap.strdup_strings = 1;
 		me->namemap.cmp = namemap_cmp;
-- 
2.2.0.rc3
Previous: Stefan BellerNext: Stefan Beller
Message 2 of 5 in “string_list: document string_list_(insert,lookup)”
  1. 1/3 string_list: document string_list_(insert,lookup)Stefan Beller, Nov 24, 2014
  2. 2/3 mailmap: use higher level string list functionsStefan Beller, Nov 24, 2014
  3. 3/3 string_list: Remove string_list_insert_at_index from its APIStefan Beller, Nov 24, 2014
  4. Junio C HamanoNov 25, 2014
  5. Stefan BellerNov 25, 2014

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.