+struct commit_slab {
+ int *buf;
+ int alloc;
+};
+
+static void slab_init(struct commit_slab *s)
+{
+ memset(s, 0, sizeof(*s));
+}
+
+static void slab_clear(struct commit_slab *s)
+{
+ free(s->buf);
+ slab_init(s);
+}
+
+static inline int *slab_at(struct commit_slab *s, const struct commit *c)
+{
+ if (s->alloc <= c->index) {
+ int new_alloc = alloc_nr(s->alloc);
+ if (new_alloc <= c->index)
+ new_alloc = c->index + 1;
+
+ s->buf = xrealloc(s->buf, new_alloc * sizeof(*s->buf));
+ memset(s->buf + s->alloc, 0, new_alloc - s->alloc);
+ s->alloc = new_alloc;
+ }
+ return s->buf + c->index;
+}
+