Skip to content

Commit a8f6c84

Browse files
poetteringkeszybz
authored andcommitted
cachunker: tiny refactor for fixed size chunker
1 parent 6464f53 commit a8f6c84

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/cachunker.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ static bool shall_break(CaChunker *c, uint32_t v) {
197197
return (v % c->discriminator) == (c->discriminator - 1);
198198
}
199199

200+
static bool CA_CHUNKER_IS_FIXED_SIZE(CaChunker *c) {
201+
return c->chunk_size_min == c->chunk_size_avg &&
202+
c->chunk_size_max == c->chunk_size_avg;
203+
}
204+
200205
size_t ca_chunker_scan(CaChunker *c, const void* p, size_t n) {
201206
const uint8_t *q = p;
202207
uint32_t v;
@@ -205,22 +210,19 @@ size_t ca_chunker_scan(CaChunker *c, const void* p, size_t n) {
205210
assert(c);
206211
assert(p);
207212

208-
/* fixed size chunker */
209-
210-
if (c->chunk_size_min == c->chunk_size_avg && c->chunk_size_max == c->chunk_size_avg) {
211-
size_t m;
212-
size_t fixed_size = c->chunk_size_avg;
213+
if (CA_CHUNKER_IS_FIXED_SIZE(c)) {
214+
/* Special case: fixed size chunker */
215+
size_t m, fixed_size = c->chunk_size_avg;
213216

214217
/* Append to window to make it full */
218+
assert(c->chunk_size < fixed_size);
215219
m = MIN(fixed_size - c->chunk_size, n);
216-
217220
c->chunk_size += m;
218221

219222
if (c->chunk_size < fixed_size)
220223
return (size_t) -1;
221224

222225
k = m;
223-
224226
goto now;
225227
}
226228

0 commit comments

Comments
 (0)