15
* - int *indegree_at(struct indegree *, struct commit *);
16
*
17
* This function locates the data associated with the given commit in
18
- * the indegree slab, and returns the pointer to it.
18
+ * the indegree slab, and returns the pointer to it. The location to
19
+ * store the data is allocated as necessary.
20
+ *
21
+ * - int *indegree_peek(struct indegree *, struct commit *);
22
+ *
23
+ * This function is similar to indegree_at(), but it will return NULL
24
+ * until a call to indegree_at() was made for the commit.
25
*
26
* - void init_indegree(struct indegree *);
27
* void init_indegree_with_stride(struct indegree *, int);
86
s->slab = NULL; \
87
} \
88
\
83
-static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s, \
84
- const struct commit *c) \
89
+static MAYBE_UNUSED elemtype *slabname## _at_peek(struct slabname *s, \
90
+ const struct commit *c, \
91
+ int add_if_missing) \
92
{ \
93
int nth_slab, nth_slot; \
94
\
97
\
98
if (s->slab_count <= nth_slab) { \
99
int i; \
100
+ if (!add_if_missing) \
101
+ return NULL; \
102
s->slab = xrealloc(s->slab, \
103
(nth_slab + 1) * sizeof(*s->slab)); \
104
stat_ ##slabname## realloc++; \
106
s->slab[i] = NULL; \
107
s->slab_count = nth_slab + 1; \
108
} \
100
- if (!s->slab[nth_slab]) \
109
+ if (!s->slab[nth_slab]) { \
110
+ if (!add_if_missing) \
111
+ return NULL; \
112
s->slab[nth_slab] = xcalloc(s->slab_size, \
113
sizeof(**s->slab) * s->stride); \
103
- return &s->slab[nth_slab][nth_slot * s->stride]; \
114
+ } \
115
+ return &s->slab[nth_slab][nth_slot * s->stride]; \
116
+} \
117
+ \
118
+static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s, \
119
+ const struct commit *c) \
120
+{ \
121
+ return slabname##_at_peek(s, c, 1); \
122
+} \
123
+ \
124
+static MAYBE_UNUSED elemtype *slabname## _peek(struct slabname *s, \
125
+ const struct commit *c) \
126
+{ \
127
+ return slabname##_at_peek(s, c, 0); \
128
} \
129
\
130
static int stat_ ##slabname## realloc