mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
shallow.c: rename fields in paint_info to better express their purposes
paint_alloc() is basically malloc(), tuned for allocating a fixed number of bits on every call without worrying about freeing any individual allocation since all will be freed at the end. It does it by allocating a big block of memory every time it runs out of "free memory". "slab" is a poor choice of name, at least poorer than "pool". Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
0202c411ed
commit
0afd307ab4
18
shallow.c
18
shallow.c
|
@ -356,9 +356,9 @@ define_commit_slab(ref_bitmap, uint32_t *);
|
||||||
struct paint_info {
|
struct paint_info {
|
||||||
struct ref_bitmap ref_bitmap;
|
struct ref_bitmap ref_bitmap;
|
||||||
unsigned nr_bits;
|
unsigned nr_bits;
|
||||||
char **slab;
|
char **pools;
|
||||||
char *free, *end;
|
char *free, *end;
|
||||||
unsigned slab_count;
|
unsigned pool_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint32_t *paint_alloc(struct paint_info *info)
|
static uint32_t *paint_alloc(struct paint_info *info)
|
||||||
|
@ -366,11 +366,11 @@ static uint32_t *paint_alloc(struct paint_info *info)
|
||||||
unsigned nr = (info->nr_bits + 31) / 32;
|
unsigned nr = (info->nr_bits + 31) / 32;
|
||||||
unsigned size = nr * sizeof(uint32_t);
|
unsigned size = nr * sizeof(uint32_t);
|
||||||
void *p;
|
void *p;
|
||||||
if (!info->slab_count || info->free + size > info->end) {
|
if (!info->pool_count || info->free + size > info->end) {
|
||||||
info->slab_count++;
|
info->pool_count++;
|
||||||
REALLOC_ARRAY(info->slab, info->slab_count);
|
REALLOC_ARRAY(info->pools, info->pool_count);
|
||||||
info->free = xmalloc(COMMIT_SLAB_SIZE);
|
info->free = xmalloc(COMMIT_SLAB_SIZE);
|
||||||
info->slab[info->slab_count - 1] = info->free;
|
info->pools[info->pool_count - 1] = info->free;
|
||||||
info->end = info->free + COMMIT_SLAB_SIZE;
|
info->end = info->free + COMMIT_SLAB_SIZE;
|
||||||
}
|
}
|
||||||
p = info->free;
|
p = info->free;
|
||||||
|
@ -546,9 +546,9 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
|
||||||
post_assign_shallow(info, &pi.ref_bitmap, ref_status);
|
post_assign_shallow(info, &pi.ref_bitmap, ref_status);
|
||||||
|
|
||||||
clear_ref_bitmap(&pi.ref_bitmap);
|
clear_ref_bitmap(&pi.ref_bitmap);
|
||||||
for (i = 0; i < pi.slab_count; i++)
|
for (i = 0; i < pi.pool_count; i++)
|
||||||
free(pi.slab[i]);
|
free(pi.pools[i]);
|
||||||
free(pi.slab);
|
free(pi.pools);
|
||||||
free(shallow);
|
free(shallow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue