tree-wide: use typesafe_bsearch() or typesafe_bsearch_r()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Sep 2018 02:08:23 +0000 (11:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Sep 2018 23:08:03 +0000 (08:08 +0900)
src/basic/strbuf.c
src/hwdb/hwdb.c
src/udev/udevadm-hwdb.c

index 275a012..81f4f21 100644 (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;
index d9a6d83..ec96923 100644 (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.
index 55bd060..12f4c46 100644 (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;