Signed-off-by: Stefan Beller <sbel...@google.com>
---
 commit.c | 29 +++++++++++++++++++++++------
 commit.h |  4 ++++
 object.c |  5 +++++
 object.h |  4 ++++
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/commit.c b/commit.c
index fe3b6ff216f..e9b22268997 100644
--- a/commit.c
+++ b/commit.c
@@ -248,18 +248,32 @@ struct commit_buffer {
        unsigned long size;
 };
 define_commit_slab(buffer_slab, struct commit_buffer);
-static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
+
+struct buffer_slab *allocate_commit_buffer_slab(void)
+{
+       struct buffer_slab *bs = xmalloc(sizeof(*bs));
+       init_buffer_slab(bs);
+       return bs;
+}
+
+void free_commit_buffer_slab(struct buffer_slab *bs)
+{
+       clear_buffer_slab(bs);
+       free(bs);
+}
 
 void set_commit_buffer_the_repository(struct commit *commit, void *buffer, 
unsigned long size)
 {
-       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_at(
+               the_repository->parsed_objects->buffer_slab, commit);
        v->buffer = buffer;
        v->size = size;
 }
 
 const void *get_cached_commit_buffer_the_repository(const struct commit 
*commit, unsigned long *sizep)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        if (!v) {
                if (sizep)
                        *sizep = 0;
@@ -291,14 +305,16 @@ 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_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        if (!(v && v->buffer == buffer))
                free((void *)buffer);
 }
 
 void free_commit_buffer(struct commit *commit)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        if (v) {
                FREE_AND_NULL(v->buffer);
                v->size = 0;
@@ -318,7 +334,8 @@ void release_commit_memory(struct commit *c)
 
 const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        void *ret;
 
        if (!v) {
diff --git a/commit.h b/commit.h
index 66aabb80068..a417f99ad4f 100644
--- a/commit.h
+++ b/commit.h
@@ -79,6 +79,10 @@ static inline int parse_commit(struct commit *item)
 }
 void parse_commit_or_die(struct commit *item);
 
+struct buffer_slab;
+struct buffer_slab *allocate_commit_buffer_slab(void);
+void free_commit_buffer_slab(struct buffer_slab *bs);
+
 /*
  * Associate an object buffer with the commit. The ownership of the
  * memory is handed over to the commit, and must be free()-able.
diff --git a/object.c b/object.c
index c1c1cbc1f53..7a7b078e4d0 100644
--- a/object.c
+++ b/object.c
@@ -467,6 +467,8 @@ struct parsed_object_pool *parsed_object_pool_new(void)
        o->is_shallow = -1;
        o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
 
+       o->buffer_slab = allocate_commit_buffer_slab();
+
        return o;
 }
 
@@ -538,6 +540,9 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
        FREE_AND_NULL(o->obj_hash);
        o->obj_hash_size = 0;
 
+       free_commit_buffer_slab(o->buffer_slab);
+       o->buffer_slab = NULL;
+
        clear_alloc_state(o->blob_state);
        clear_alloc_state(o->tree_state);
        clear_alloc_state(o->commit_state);
diff --git a/object.h b/object.h
index 66e0b7b93dc..876480c933c 100644
--- a/object.h
+++ b/object.h
@@ -1,6 +1,8 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
+struct buffer_slab;
+
 struct parsed_object_pool {
        struct object **obj_hash;
        int nr_objs, obj_hash_size;
@@ -22,6 +24,8 @@ struct parsed_object_pool {
        char *alternate_shallow_file;
 
        int commit_graft_prepared;
+
+       struct buffer_slab *buffer_slab;
 };
 
 struct parsed_object_pool *parsed_object_pool_new(void);
-- 
2.18.0.rc1.244.gcf134e6275-goog

Reply via email to