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

Re: [PATCH] merge: use string_list_split() in add_strategies()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 8, 2016, 08:39 UTC
Message-ID
<alpine.DEB.2.20.1608081034250.5786@virtualbox>
In-Reply-To
<57A4FEAF.3040208@web.de>
Hi René,
On Fri, 5 Aug 2016, René Scharfe wrote:
Show 21 quoted lines
>  static void add_strategies(const char *string, unsigned attr)
>  {
> -	struct strategy *list = NULL;
> -	int list_alloc = 0, list_nr = 0, i;
> -
> -	memset(&list, 0, sizeof(list));
> -	split_merge_strategies(string, &list, &list_nr, &list_alloc);
> -	if (list) {
> -		for (i = 0; i < list_nr; i++)
> -			append_strategy(get_strategy(list[i].name));
> +	int i;
> +
> +	if (string) {
> +		struct string_list list = STRING_LIST_INIT_DUP;
> +		struct string_list_item *item;
> +		string_list_split(&list, string, ' ', -1);
> +		for_each_string_list_item(item, &list)
> +			append_strategy(get_strategy(item->string));
> +		string_list_clear(&list, 0);
>  		return;
>  	}
A nice code reduction!

I wonder, however, if we could somhow turn things around by introducing something like

	split_and_do_for_each(item_p, length, string, delimiter)
		... <do something with item_p and length> ...

that both string_list_split() *and* add_strategies() could use? We would then be able to avoid allocating the list and duplicating the items in the latter case.

Ciao, Dscho

Previous: René ScharfeNext: Junio C Hamano
Message 2 of 6 in “merge: use string_list_split() in add_strategies()”
  1. merge: use string_list_split() in add_strategies()René Scharfe, Aug 5, 2016
  2. Johannes SchindelinAug 8, 2016
  3. Junio C HamanoAug 8, 2016
  4. Junio C HamanoAug 8, 2016
  5. Johannes SchindelinAug 10, 2016
  6. Junio C HamanoAug 10, 2016

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.