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

Re: [PATCH 0/3] Using a bit more decoration

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 9, 2013, 20:06 UTC
Message-ID
<7v8v4rqxj6.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130409065256.GA20115@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 13 quoted lines
> +static inline int *slab_at(struct commit_slab *s, const struct commit *c)
> +{
> +	if (s->alloc <= c->index) {
> +		int new_alloc = alloc_nr(s->alloc);
> +		if (new_alloc <= c->index)
> +			new_alloc = c->index + 1;
> +
> +		s->buf = xrealloc(s->buf, new_alloc * sizeof(*s->buf));
> +		memset(s->buf + s->alloc, 0, new_alloc - s->alloc);
> +		s->alloc = new_alloc;
> +	}
> +	return s->buf + c->index;
> +}

This will hurt more as the number of objects we deal with grows (our ALLOC_GROW() shares the same).

I wonder if it might be a good idea to do
	struct commit_slab {
        	int piece_size;
		int piece_count;
		struct commit_slab_piece {
                	int *buf;
		} *piece;
	};
and then make the look-up logic like this:
	int nth_piece, nth_slot;
	nth_piece = c->index / s->piece_size;
        nth_slot = c->index % s->piece_size;
        if (s->piece_count <= nth_piece) {
		/* xrealloc s->piece to grow, update s->piece_count */
        }
        if (!s->piece[nth_piece]) {
		/* xcalloc s->piece[nth_piece] to allocate */
	}
        return s->piece[nth_piece]->buf + nth_slot;
Other than that, looks like a good technology demonstration.
Previous: Jeff KingNext: Junio C Hamano
Message 14 of 15 in “decorate: add "clear_decoration()"”
  1. 2/2 decorate: add "clear_decoration()"Junio C Hamano, Apr 8, 2013
  2. Jeff KingApr 8, 2013
  3. Junio C HamanoApr 8, 2013
  4. 0/3 Using a bit more decorationJunio C Hamano, Apr 8, 2013
  5. 1/3 commit: shrink "indegree" fieldJunio C Hamano, Apr 8, 2013
  6. Jeff KingApr 9, 2013
  7. 2/3 commit: rename parse_commit_date()Junio C Hamano, Apr 8, 2013
  8. 3/3 commit: add get_commit_encoding()Junio C Hamano, Apr 8, 2013
  9. Jeff KingApr 9, 2013
  10. Junio C HamanoApr 9, 2013
  11. Jeff KingApr 9, 2013
  12. Junio C HamanoApr 9, 2013
  13. Jeff KingApr 9, 2013
  14. Junio C HamanoApr 9, 2013
  15. Junio C HamanoApr 9, 2013

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.