Skip to content

Commit

Permalink
Merge branch 'rj/commit-slab-fix'
Browse files Browse the repository at this point in the history
* rj/commit-slab-fix:
  commit-slab.h: Fix memory allocation and addressing
  • Loading branch information
Junio C Hamano committed Jul 31, 2013
2 parents af77c0b + d7a1d62 commit 2ed8eca
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions commit-slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void init_ ##slabname## _with_stride(struct slabname *s, \
if (!stride) \
stride = 1; \
s->stride = stride; \
elem_size = sizeof(struct slabname) * stride; \
elem_size = sizeof(elemtype) * stride; \
s->slab_size = COMMIT_SLAB_SIZE / elem_size; \
s->slab_count = 0; \
s->slab = NULL; \
Expand All @@ -72,11 +72,10 @@ static void clear_ ##slabname(struct slabname *s) \
static elemtype *slabname## _at(struct slabname *s, \
const struct commit *c) \
{ \
int nth_slab, nth_slot, ix; \
int nth_slab, nth_slot; \
\
ix = c->index * s->stride; \
nth_slab = ix / s->slab_size; \
nth_slot = ix % s->slab_size; \
nth_slab = c->index / s->slab_size; \
nth_slot = c->index % s->slab_size; \
\
if (s->slab_count <= nth_slab) { \
int i; \
Expand All @@ -89,8 +88,8 @@ static elemtype *slabname## _at(struct slabname *s, \
} \
if (!s->slab[nth_slab]) \
s->slab[nth_slab] = xcalloc(s->slab_size, \
sizeof(**s->slab)); \
return &s->slab[nth_slab][nth_slot]; \
sizeof(**s->slab) * s->stride); \
return &s->slab[nth_slab][nth_slot * s->stride]; \
} \
\
static int stat_ ##slabname## realloc
Expand Down

0 comments on commit 2ed8eca

Please sign in to comment.