summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-10 21:43:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-13 19:08:17 (GMT)
commitc1b3c71f4b4571abb2b2a457122fd100dc9f7eb0 (patch)
treec6d4ff6717e8f95c83147f4d97c5a90ca6d3029b /commit.c
parent80cdaba569600154d91819d2e252f6b7dd9cff73 (diff)
downloadgit-c1b3c71f4b4571abb2b2a457122fd100dc9f7eb0.zip
git-c1b3c71f4b4571abb2b2a457122fd100dc9f7eb0.tar.gz
git-c1b3c71f4b4571abb2b2a457122fd100dc9f7eb0.tar.bz2
commit: convert commit->buffer to a slab
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>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/commit.c b/commit.c
index 1903dde..e289c78 100644
--- a/commit.c
+++ b/commit.c
@@ -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)
@@ -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;
}