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

[PATCH 1/4] parse-options: use COPY_ARRAY in parse_options_concat()

From
René Scharfe <l.s.r@web.de>
Date
Feb 9, 2020, 15:55 UTC
Message-ID
<074eda38-9517-26b6-5608-55ec5f473d80@web.de>
In-Reply-To
<11b82734-f61c-5e73-2d0c-22208c06d495@web.de>

Use COPY_ARRAY to copy whole arrays instead of iterating through the elements. That's shorter, simpler and bit more efficient.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 parse-options-cb.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/parse-options-cb.c b/parse-options-cb.c
index c2062ae742..012e048856 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -188,11 +188,8 @@ struct option *parse_options_concat(struct option *a, struct option *b)
 		b_len++;

 	ALLOC_ARRAY(ret, st_add3(a_len, b_len, 1));
-	for (i = 0; i < a_len; i++)
-		ret[i] = a[i];
-	for (i = 0; i < b_len; i++)
-		ret[a_len + i] = b[i];
-	ret[a_len + b_len] = b[b_len]; /* final OPTION_END */
+	COPY_ARRAY(ret, a, a_len);
+	COPY_ARRAY(ret + a_len, b, b_len + 1); /* + 1 for final OPTION_END */

 	return ret;
 }
--
2.25.0
Previous: René ScharfeNext: René Scharfe
Message 2 of 9 in “parse-options: simplify parse_options_concat() and parse_options_dup()”
  1. 0/4 parse-options: simplify parse_options_concat() and parse_options_dup()René Scharfe, Feb 9, 2020
  2. 1/4 parse-options: use COPY_ARRAY in parse_options_concat()René Scharfe, Feb 9, 2020
  3. 2/4 parse-options: factor out parse_options_count()René Scharfe, Feb 9, 2020
  4. Eric SunshineFeb 9, 2020
  5. René ScharfeFeb 9, 2020
  6. 3/4 parse-options: const parse_options_concat() parametersRené Scharfe, Feb 9, 2020
  7. 4/4 parse-options: simplify parse_options_dup()René Scharfe, Feb 9, 2020
  8. Junio C HamanoFeb 10, 2020
  9. Jeff KingFeb 10, 2020

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.