git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] merge: use string_list_split() in add_strategies()
Date: Mon, 8 Aug 2016 10:39:08 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1608081034250.5786@virtualbox> (raw)
In-Reply-To: <57A4FEAF.3040208@web.de>

[-- Attachment #1: Type: text/plain, Size: 1155 bytes --]

Hi René,

On Fri, 5 Aug 2016, René Scharfe wrote:

>  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

  reply	other threads:[~2016-08-08  8:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-05 21:01 [PATCH] merge: use string_list_split() in add_strategies() René Scharfe
2016-08-08  8:39 ` Johannes Schindelin [this message]
2016-08-08 17:55   ` Junio C Hamano
2016-08-08 20:11     ` Junio C Hamano
2016-08-10 12:31     ` Johannes Schindelin
2016-08-10 16:33       ` 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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1608081034250.5786@virtualbox \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).