[PATCH] wayland-util: merge {client, server}_entries in wl_map into one variable

Chang Liu cl91tp at gmail.com
Sun Sep 8 04:12:01 PDT 2013


Since a wl_map can be either client side or server side (but not both)
and we have the side field to indicate this, we can merge client_entries
and server_entries into one variable to reduce clutter.
---
 src/wayland-private.h |  3 +--
 src/wayland-util.c    | 43 +++++++++++--------------------------------
 2 files changed, 12 insertions(+), 34 deletions(-)

diff --git a/src/wayland-private.h b/src/wayland-private.h
index 5b3715d..68f4ee4 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -60,8 +60,7 @@ enum wl_map_entry_flags {
 };
 
 struct wl_map {
-	struct wl_array client_entries;
-	struct wl_array server_entries;
+	struct wl_array entries;
 	uint32_t side;
 	uint64_t free_list;
 };
diff --git a/src/wayland-util.c b/src/wayland-util.c
index 1798fd6..2fc8b17 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -167,22 +167,19 @@ wl_map_init(struct wl_map *map, uint32_t side)
 WL_EXPORT void
 wl_map_release(struct wl_map *map)
 {
-	wl_array_release(&map->client_entries);
-	wl_array_release(&map->server_entries);
+	wl_array_release(&map->entries);
 }
 
 WL_EXPORT uint32_t
 wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data)
 {
 	union map_entry *start, *entry;
-	struct wl_array *entries;
+	struct wl_array *entries = &map->entries;
 	uint32_t base;
 
 	if (map->side == WL_MAP_CLIENT_SIDE) {
-		entries = &map->client_entries;
 		base = 0;
 	} else {
-		entries = &map->server_entries;
 		base = WL_SERVER_ID_START;
 	}
 
@@ -208,12 +205,9 @@ wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data)
 {
 	union map_entry *start;
 	uint32_t count;
-	struct wl_array *entries;
+	struct wl_array *entries = &map->entries;
 
-	if (i < WL_SERVER_ID_START) {
-		entries = &map->client_entries;
-	} else {
-		entries = &map->server_entries;
+	if (i >= WL_SERVER_ID_START) {
 		i -= WL_SERVER_ID_START;
 	}
 
@@ -236,18 +230,14 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)
 {
 	union map_entry *start;
 	uint32_t count;
-	struct wl_array *entries;
+	struct wl_array *entries = &map->entries;
 
 	if (i < WL_SERVER_ID_START) {
 		if (map->side == WL_MAP_CLIENT_SIDE)
 			return -1;
-
-		entries = &map->client_entries;
 	} else {
 		if (map->side == WL_MAP_SERVER_SIDE)
 			return -1;
-
-		entries = &map->server_entries;
 		i -= WL_SERVER_ID_START;
 	}
 
@@ -274,18 +264,14 @@ WL_EXPORT void
 wl_map_remove(struct wl_map *map, uint32_t i)
 {
 	union map_entry *start;
-	struct wl_array *entries;
+	struct wl_array *entries = &map->entries;
 
 	if (i < WL_SERVER_ID_START) {
 		if (map->side == WL_MAP_SERVER_SIDE)
 			return;
-
-		entries = &map->client_entries;
 	} else {
 		if (map->side == WL_MAP_CLIENT_SIDE)
 			return;
-
-		entries = &map->server_entries;
 		i -= WL_SERVER_ID_START;
 	}
 
@@ -299,12 +285,9 @@ wl_map_lookup(struct wl_map *map, uint32_t i)
 {
 	union map_entry *start;
 	uint32_t count;
-	struct wl_array *entries;
+	struct wl_array *entries = &map->entries;
 
-	if (i < WL_SERVER_ID_START) {
-		entries = &map->client_entries;
-	} else {
-		entries = &map->server_entries;
+	if (i >= WL_SERVER_ID_START) {
 		i -= WL_SERVER_ID_START;
 	}
 
@@ -322,12 +305,9 @@ wl_map_lookup_flags(struct wl_map *map, uint32_t i)
 {
 	union map_entry *start;
 	uint32_t count;
-	struct wl_array *entries;
+	struct wl_array *entries = &map->entries;
 
-	if (i < WL_SERVER_ID_START) {
-		entries = &map->client_entries;
-	} else {
-		entries = &map->server_entries;
+	if (i >= WL_SERVER_ID_START) {
 		i -= WL_SERVER_ID_START;
 	}
 
@@ -356,8 +336,7 @@ for_each_helper(struct wl_array *entries, wl_iterator_func_t func, void *data)
 WL_EXPORT void
 wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
 {
-	for_each_helper(&map->client_entries, func, data);
-	for_each_helper(&map->server_entries, func, data);
+	for_each_helper(&map->entries, func, data);
 }
 
 static void
-- 
1.8.3.4



More information about the wayland-devel mailing list