diff options
| author | Ben Pfaff <blp@nicira.com> | 2010-09-17 10:33:10 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2010-10-01 10:25:29 -0700 |
| commit | 4e8e4213a815a30216e855a805a8bcd5b8c5a886 (patch) | |
| tree | 38dbb503be4f22ae804f3e5f83459c975d83886a /lib/hmap.h | |
| parent | adf7cfd851c3d9d6f1ad74653cbd2fecce8c3ba9 (diff) | |
| download | openvswitch-4e8e4213a815a30216e855a805a8bcd5b8c5a886.tar.gz | |
Switch many macros from using CONTAINER_OF to using OBJECT_CONTAINING.
These macros require one fewer argument by switching, which makes code
that uses them shorter and more readable.
Diffstat (limited to 'lib/hmap.h')
| -rw-r--r-- | lib/hmap.h | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/lib/hmap.h b/lib/hmap.h index 92aff7f99..04e51bc6d 100644 --- a/lib/hmap.h +++ b/lib/hmap.h @@ -96,9 +96,8 @@ struct hmap_node *hmap_random_node(const struct hmap *); * * HMAP_FOR_EACH_WITH_HASH iterates NODE over all of the nodes in HMAP that * have hash value equal to HASH. HMAP_FOR_EACH_IN_BUCKET iterates NODE over - * all of the nodes in HMAP that would fall in the same bucket as HASH. STRUCT - * and MEMBER must be the name of the struct that contains the 'struct - * hmap_node' and the name of the 'struct hmap_node' member, respectively. + * all of the nodes in HMAP that would fall in the same bucket as HASH. MEMBER + * must be the name of the 'struct hmap_node' member within NODE. * * These macros may be used interchangeably to search for a particular value in * an hmap, see, e.g. shash_find() for an example. Usually, using @@ -113,18 +112,18 @@ struct hmap_node *hmap_random_node(const struct hmap *); * * HASH is only evaluated once. */ -#define HMAP_FOR_EACH_WITH_HASH(NODE, STRUCT, MEMBER, HASH, HMAP) \ - for ((NODE) = CONTAINER_OF(hmap_first_with_hash(HMAP, HASH), \ - STRUCT, MEMBER); \ +#define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP) \ + for ((NODE) = OBJECT_CONTAINING(hmap_first_with_hash(HMAP, HASH), \ + NODE, MEMBER); \ &(NODE)->MEMBER != NULL; \ - (NODE) = CONTAINER_OF(hmap_next_with_hash(&(NODE)->MEMBER), \ - STRUCT, MEMBER)) -#define HMAP_FOR_EACH_IN_BUCKET(NODE, STRUCT, MEMBER, HASH, HMAP) \ - for ((NODE) = CONTAINER_OF(hmap_first_in_bucket(HMAP, HASH), \ - STRUCT, MEMBER); \ + (NODE) = OBJECT_CONTAINING(hmap_next_with_hash(&(NODE)->MEMBER), \ + NODE, MEMBER)) +#define HMAP_FOR_EACH_IN_BUCKET(NODE, MEMBER, HASH, HMAP) \ + for ((NODE) = OBJECT_CONTAINING(hmap_first_in_bucket(HMAP, HASH), \ + NODE, MEMBER); \ &(NODE)->MEMBER != NULL; \ - (NODE) = CONTAINER_OF(hmap_next_in_bucket(&(NODE)->MEMBER), \ - STRUCT, MEMBER)) + (NODE) = OBJECT_CONTAINING(hmap_next_in_bucket(&(NODE)->MEMBER), \ + NODE, MEMBER)) static inline struct hmap_node *hmap_first_with_hash(const struct hmap *, size_t hash); @@ -138,18 +137,18 @@ static inline struct hmap_node *hmap_next_in_bucket(const struct hmap_node *); * The _SAFE version is needed when NODE may be freed. It is not needed when * NODE may be removed from the hash map but its members remain accessible and * intact. */ -#define HMAP_FOR_EACH(NODE, STRUCT, MEMBER, HMAP) \ - for ((NODE) = CONTAINER_OF(hmap_first(HMAP), STRUCT, MEMBER); \ - &(NODE)->MEMBER != NULL; \ - (NODE) = CONTAINER_OF(hmap_next(HMAP, &(NODE)->MEMBER), \ - STRUCT, MEMBER)) - -#define HMAP_FOR_EACH_SAFE(NODE, NEXT, STRUCT, MEMBER, HMAP) \ - for ((NODE) = CONTAINER_OF(hmap_first(HMAP), STRUCT, MEMBER); \ - (&(NODE)->MEMBER != NULL \ - ? (NEXT) = CONTAINER_OF(hmap_next(HMAP, &(NODE)->MEMBER), \ - STRUCT, MEMBER), 1 \ - : 0); \ +#define HMAP_FOR_EACH(NODE, MEMBER, HMAP) \ + for ((NODE) = OBJECT_CONTAINING(hmap_first(HMAP), NODE, MEMBER); \ + &(NODE)->MEMBER != NULL; \ + (NODE) = OBJECT_CONTAINING(hmap_next(HMAP, &(NODE)->MEMBER), \ + NODE, MEMBER)) + +#define HMAP_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HMAP) \ + for ((NODE) = OBJECT_CONTAINING(hmap_first(HMAP), NODE, MEMBER); \ + (&(NODE)->MEMBER != NULL \ + ? (NEXT) = OBJECT_CONTAINING(hmap_next(HMAP, &(NODE)->MEMBER), \ + NODE, MEMBER), 1 \ + : 0); \ (NODE) = (NEXT)) static inline struct hmap_node *hmap_first(const struct hmap *); |
