Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit c1b3c71

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80cdaba commit c1b3c71

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

commit.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,17 @@ int unregister_shallow(const unsigned char *sha1)
245245
return 0;
246246
}
247247

248+
define_commit_slab(buffer_slab, void *);
249+
static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
250+
248251
void set_commit_buffer(struct commit *commit, void *buffer)
249252
{
250-
commit->buffer = buffer;
253+
*buffer_slab_at(&buffer_slab, commit) = buffer;
251254
}
252255

253256
const void *get_cached_commit_buffer(const struct commit *commit)
254257
{
255-
return commit->buffer;
258+
return *buffer_slab_at(&buffer_slab, commit);
256259
}
257260

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

275278
void unuse_commit_buffer(const struct commit *commit, const void *buffer)
276279
{
277-
if (commit->buffer != buffer)
280+
void *cached = *buffer_slab_at(&buffer_slab, commit);
281+
if (cached != buffer)
278282
free((void *)buffer);
279283
}
280284

281285
void free_commit_buffer(struct commit *commit)
282286
{
283-
free(commit->buffer);
284-
commit->buffer = NULL;
287+
void **b = buffer_slab_at(&buffer_slab, commit);
288+
free(*b);
289+
*b = NULL;
285290
}
286291

287292
const void *detach_commit_buffer(struct commit *commit)
288293
{
289-
void *ret = commit->buffer;
290-
commit->buffer = NULL;
294+
void **b = buffer_slab_at(&buffer_slab, commit);
295+
void *ret = *b;
296+
*b = NULL;
291297
return ret;
292298
}
293299

commit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct commit {
2020
unsigned long date;
2121
struct commit_list *parents;
2222
struct tree *tree;
23-
char *buffer;
2423
};
2524

2625
extern int save_commit_buffer;

0 commit comments

Comments
 (0)