tree-wide: use typesafe_bsearch() or typesafe_bsearch_r()

This commit is contained in:
Yu Watanabe 2018-09-18 11:08:23 +09:00
parent f0f6d791fe
commit bc861c2e09
3 changed files with 5 additions and 9 deletions

View File

@ -142,9 +142,7 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
/* lookup child node */
search.c = c;
child = bsearch_safe(&search, node->children, node->children_count,
sizeof(struct strbuf_child_entry),
(__compar_fn_t) strbuf_children_cmp);
child = typesafe_bsearch(&search, node->children, node->children_count, strbuf_children_cmp);
if (!child)
break;
node = child->child;

View File

@ -104,7 +104,7 @@ static struct trie_node *node_lookup(const struct trie_node *node, uint8_t c) {
struct trie_child_entry search;
search.c = c;
child = bsearch_safe(&search, node->children, node->children_count, sizeof(struct trie_child_entry), (comparison_fn_t) trie_children_cmp);
child = typesafe_bsearch(&search, node->children, node->children_count, trie_children_cmp);
if (child)
return child->child;
return NULL;
@ -160,7 +160,7 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
.value_off = v,
};
val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), (__compar_d_fn_t) trie_values_cmp, trie);
val = typesafe_bsearch_r(&search, node->values, node->values_count, trie_values_cmp, trie);
if (val) {
/* At this point we have 2 identical properties on the same match-string.
* Since we process files in order, we just replace the previous value.

View File

@ -100,9 +100,7 @@ static struct trie_node *node_lookup(const struct trie_node *node, uint8_t c) {
struct trie_child_entry search;
search.c = c;
child = bsearch_safe(&search,
node->children, node->children_count, sizeof(struct trie_child_entry),
(comparison_fn_t) trie_children_cmp);
child = typesafe_bsearch(&search, node->children, node->children_count, trie_children_cmp);
if (child)
return child->child;
return NULL;
@ -155,7 +153,7 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
.value_off = v,
};
val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), (__compar_d_fn_t) trie_values_cmp, trie);
val = typesafe_bsearch_r(&search, node->values, node->values_count, trie_values_cmp, trie);
if (val) {
/* replace existing earlier key with new value */
val->value_off = v;