return a[i] == b[i];
}
-int common_prefix_size(struct reftable_buf *a, struct reftable_buf *b)
+size_t common_prefix_size(struct reftable_buf *a, struct reftable_buf *b)
{
- int p = 0;
- for (; p < a->len && p < b->len; p++) {
+ size_t p = 0;
+ for (; p < a->len && p < b->len; p++)
if (a->buf[p] != b->buf[p])
break;
- }
-
return p;
}
#endif
/* Find the longest shared prefix size of `a` and `b` */
-int common_prefix_size(struct reftable_buf *a, struct reftable_buf *b);
+size_t common_prefix_size(struct reftable_buf *a, struct reftable_buf *b);
int hash_size(enum reftable_hash id);
uint8_t extra)
{
struct string_view start = dest;
- int prefix_len = common_prefix_size(&prev_key, &key);
+ size_t prefix_len = common_prefix_size(&prev_key, &key);
uint64_t suffix_len = key.len - prefix_len;
- int n = put_var_int(&dest, (uint64_t)prefix_len);
+ int n = put_var_int(&dest, prefix_len);
if (n < 0)
return -1;
string_view_consume(&dest, n);
struct common_prefix_arg {
struct reftable_buf *last;
- int max;
+ size_t max;
};
static void update_common(void *void_arg, void *key)
struct common_prefix_arg *arg = void_arg;
struct obj_index_tree_node *entry = key;
if (arg->last) {
- int n = common_prefix_size(&entry->hash, arg->last);
- if (n > arg->max) {
+ size_t n = common_prefix_size(&entry->hash, arg->last);
+ if (n > arg->max)
arg->max = n;
- }
}
arg->last = &entry->hash;
}
for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
check(!reftable_buf_addstr(&a, cases[i].a));
check(!reftable_buf_addstr(&b, cases[i].b));
- check_int(common_prefix_size(&a, &b), ==, cases[i].want);
+ check_uint(common_prefix_size(&a, &b), ==, cases[i].want);
reftable_buf_reset(&a);
reftable_buf_reset(&b);
}