Skip to content

Commit

Permalink
commit: convert commit->buffer to a slab
Browse files Browse the repository at this point in the history
This will make it easier to manage the buffer cache
independently of the "struct commit" objects. It also
shrinks "struct commit" by one pointer, which may be
helpful.

Unfortunately it does not reduce the max memory size of
something like "rev-list", because rev-list uses
get_cached_commit_buffer() to decide not to show each
commit's output (and due to the design of slab_at, accessing
the slab requires us to extend it, allocating exactly the
same number of buffer pointers we dropped from the commit
structs).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 13, 2014
1 parent 80cdaba commit c1b3c71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 13 additions & 7 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,17 @@ int unregister_shallow(const unsigned char *sha1)
return 0;
}

define_commit_slab(buffer_slab, void *);
static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);

void set_commit_buffer(struct commit *commit, void *buffer)
{
commit->buffer = buffer;
*buffer_slab_at(&buffer_slab, commit) = buffer;
}

const void *get_cached_commit_buffer(const struct commit *commit)
{
return commit->buffer;
return *buffer_slab_at(&buffer_slab, commit);
}

const void *get_commit_buffer(const struct commit *commit)
Expand All @@ -274,20 +277,23 @@ const void *get_commit_buffer(const struct commit *commit)

void unuse_commit_buffer(const struct commit *commit, const void *buffer)
{
if (commit->buffer != buffer)
void *cached = *buffer_slab_at(&buffer_slab, commit);
if (cached != buffer)
free((void *)buffer);
}

void free_commit_buffer(struct commit *commit)
{
free(commit->buffer);
commit->buffer = NULL;
void **b = buffer_slab_at(&buffer_slab, commit);
free(*b);
*b = NULL;
}

const void *detach_commit_buffer(struct commit *commit)
{
void *ret = commit->buffer;
commit->buffer = NULL;
void **b = buffer_slab_at(&buffer_slab, commit);
void *ret = *b;
*b = NULL;
return ret;
}

Expand Down
1 change: 0 additions & 1 deletion commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct commit {
unsigned long date;
struct commit_list *parents;
struct tree *tree;
char *buffer;
};

extern int save_commit_buffer;
Expand Down

0 comments on commit c1b3c71

Please sign in to comment.