Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
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: Thu, 10 Jul 2014 20:09:56 -0400	[thread overview]
Message-ID: <20140711000956.GA11360@sigill.intra.peff.net> (raw)
In-Reply-To: <53BF28A7.7000903@ramsay1.demon.co.uk>

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.

-Peff

  reply	other threads:[~2014-07-11  0:10 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 [this message]
2014-07-11  0:33   ` Ramsay Jones

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=20140711000956.GA11360@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ramsay@ramsay1.demon.co.uk \
    /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