summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-03 11:01:21 -0700
committerJunio C Hamano <gitster@pobox.com>2015-08-03 11:01:21 -0700
commit720e20eb68a476d43e59b9bd568da6cc4932a5ef (patch)
treea13a28ef30f5b6da333b26fa27b7e34ceab8c418 /commit.c
parent2dded96052114c7b902d90f80f75a30eb64d860a (diff)
parent862e730ec1c13f28bfb7c8c9ecb39bcc92dd0922 (diff)
downloadgit-720e20eb68a476d43e59b9bd568da6cc4932a5ef.tar.gz
Merge branch 'jc/commit-slab'
Memory use reduction when commit-slab facility is used to annotate sparsely (which is not recommended in the first place). * jc/commit-slab: commit-slab: introduce slabname##_peek() function
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/commit.c b/commit.c
index 62223a33e5..494615d6ff 100644
--- a/commit.c
+++ b/commit.c
@@ -245,7 +245,12 @@ void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size)
const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep)
{
- struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+ struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+ if (!v) {
+ if (sizep)
+ *sizep = 0;
+ return NULL;
+ }
if (sizep)
*sizep = v->size;
return v->buffer;
@@ -272,24 +277,31 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
void unuse_commit_buffer(const struct commit *commit, const void *buffer)
{
- struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
- if (v->buffer != buffer)
+ struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+ if (!(v && v->buffer == buffer))
free((void *)buffer);
}
void free_commit_buffer(struct commit *commit)
{
- struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
- free(v->buffer);
- v->buffer = NULL;
- v->size = 0;
+ struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+ if (v) {
+ free(v->buffer);
+ v->buffer = NULL;
+ v->size = 0;
+ }
}
const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
{
- struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+ struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
void *ret;
+ if (!v) {
+ if (sizep)
+ *sizep = 0;
+ return NULL;
+ }
ret = v->buffer;
if (sizep)
*sizep = v->size;