Git development
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
	GIT Mailing-list <git@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] alloc.c: remove the alloc_raw_commit_node() function
Date: Fri, 11 Jul 2014 01:33:24 +0100	[thread overview]
Message-ID: <53BF30D4.7010105@ramsay1.demon.co.uk> (raw)
In-Reply-To: <20140711000956.GA11360@sigill.intra.peff.net>

On 11/07/14 01:09, Jeff King wrote:
> On Fri, Jul 11, 2014 at 12:58:31AM +0100, Ramsay Jones wrote:
> 
>>  #define DEFINE_ALLOCATOR(name, type)				\
>> -static unsigned int name##_allocs;				\
>> +static struct alloc_state name##_state;				\
>>  void *alloc_##name##_node(void)					\
>>  {								\
>> -	static int nr;						\
>> -	static type *block;					\
>> -	void *ret;						\
>> -								\
>> -	if (!nr) {						\
>> -		nr = BLOCKING;					\
>> -		block = xmalloc(BLOCKING * sizeof(type));	\
>> -	}							\
>> -	nr--;							\
>> -	name##_allocs++;					\
>> -	ret = block++;						\
>> -	memset(ret, 0, sizeof(type));				\
>> -	return ret;						\
>> +	return alloc_node(&name##_state, sizeof(type));		\
>>  }
> 
> Yay. Not only does this solve the problem, but it gets rid of nasty
> multi-line macro. In fact, I kind of wonder if we should just do away
> with the macro entirely, and write out:
> 
>   static struct alloc_state blob_state;
>   void alloc_blob_node(void)
>   {
> 	return alloc_node(&blob_state, sizeof(struct blob));
>   }
> 
> It's more lines, but it is probably less obfuscated to a reader.

Yeah, I'm not a fan of _large_ multi-line macros myself.

Now that DEFINE_ALLOCATOR has slimmed down, I don't mind it so much.
However, I agree that doing away with the macro leads to easier to
read code. (I also don't mind the extra lines).

ATB,
Ramsay Jones

      reply	other threads:[~2014-07-11  0:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-10 23:58 [PATCH v3 1/2] alloc.c: remove the alloc_raw_commit_node() function Ramsay Jones
2014-07-11  0:09 ` Jeff King
2014-07-11  0:33   ` Ramsay Jones [this message]

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

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

  git send-email \
    --in-reply-to=53BF30D4.7010105@ramsay1.demon.co.uk \
    --to=ramsay@ramsay1.demon.co.uk \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox