From: Felix Fietkau Date: Sun, 2 Oct 2011 17:40:03 +0000 (+0200) Subject: vlist: store a pointer to the real key to make lookups easier X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=13ec81ce3e2f77504818de0bf89a2a1edd7e0ba2;p=oweals%2Fnetifd.git vlist: store a pointer to the real key to make lookups easier --- diff --git a/interface-ip.c b/interface-ip.c index 0845169..2d7a2d0 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -13,19 +13,15 @@ static int addr_cmp(const void *k1, const void *k2, void *ptr) { - const struct device_addr *a1 = k1, *a2 = k2; - - return memcmp(&a1->mask, &a2->mask, - sizeof(*a1) - offsetof(struct device_addr, mask)); + return memcmp(k1, k2, sizeof(struct device_addr) - + offsetof(struct device_addr, mask)); } static int route_cmp(const void *k1, const void *k2, void *ptr) { - const struct device_route *r1 = k1, *r2 = k2; - - return memcmp(&r1->mask, &r2->mask, - sizeof(*r1) - offsetof(struct device_route, mask)); + return memcmp(k1, k2, sizeof(struct device_route) - + offsetof(struct device_route, mask)); } static void @@ -84,7 +80,7 @@ void interface_ip_init(struct interface *iface) { vlist_init(&iface->proto_route, route_cmp, interface_update_proto_route, - struct device_route, node); + struct device_route, node, mask); vlist_init(&iface->proto_addr, addr_cmp, interface_update_proto_addr, - struct device_addr, node); + struct device_addr, node, mask); } diff --git a/utils.c b/utils.c index a67a8c9..cc22290 100644 --- a/utils.c +++ b/utils.c @@ -11,7 +11,7 @@ void __vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update, int offset) { - tree->node_offset = offset; + tree->key_offset = offset; tree->update = update; tree->version = 1; @@ -30,7 +30,7 @@ vlist_add(struct vlist_tree *tree, struct vlist_node *node) { struct vlist_node *old_node = NULL; struct avl_node *anode; - void *key = (char *) node - tree->node_offset; + void *key = (char *) node + tree->key_offset; node->avl.key = key; node->version = tree->version; diff --git a/utils.h b/utils.h index ab73930..31fcd1f 100644 --- a/utils.h +++ b/utils.h @@ -27,7 +27,7 @@ struct vlist_tree { struct avl_tree avl; vlist_update_cb update; - int node_offset; + int key_offset; bool keep_old; int version; @@ -40,8 +40,8 @@ struct vlist_node { void __vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update, int offset); -#define vlist_init(tree, cmp, update, type, node) \ - __vlist_init(tree, cmp, update, offsetof(type, node)) +#define vlist_init(tree, cmp, update, type, node, key) \ + __vlist_init(tree, cmp, update, offsetof(type, key) - offsetof(type, node)) void vlist_add(struct vlist_tree *tree, struct vlist_node *node); void vlist_delete(struct vlist_tree *tree, struct vlist_node *node);