<div dir="ltr">Chang,<div style>This patch is, unfortunately, incorrect.  Yes, we have a side field that tells us which side the wl_map was allocated for.  However, we use one wl_map to store both client-side and server-side IDs.  The side field, together with the WL_SERVER_ID_START, allow us to keep everything straight in the two arrays.  If we replace them by one array, then the client-side and server-side lists will overlap, conflict, and cause massive problems.</div>
<div style>Thanks,</div><div style>--Jason Ekstrand</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Sep 8, 2013 at 6:12 AM, Chang Liu <span dir="ltr"><<a href="mailto:cl91tp@gmail.com" target="_blank">cl91tp@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Since a wl_map can be either client side or server side (but not both)<br>
and we have the side field to indicate this, we can merge client_entries<br>
and server_entries into one variable to reduce clutter.<br>
---<br>
 src/wayland-private.h |  3 +--<br>
 src/wayland-util.c    | 43 +++++++++++--------------------------------<br>
 2 files changed, 12 insertions(+), 34 deletions(-)<br>
<br>
diff --git a/src/wayland-private.h b/src/wayland-private.h<br>
index 5b3715d..68f4ee4 100644<br>
--- a/src/wayland-private.h<br>
+++ b/src/wayland-private.h<br>
@@ -60,8 +60,7 @@ enum wl_map_entry_flags {<br>
 };<br>
<br>
 struct wl_map {<br>
-       struct wl_array client_entries;<br>
-       struct wl_array server_entries;<br>
+       struct wl_array entries;<br>
        uint32_t side;<br>
        uint64_t free_list;<br>
 };<br>
diff --git a/src/wayland-util.c b/src/wayland-util.c<br>
index 1798fd6..2fc8b17 100644<br>
--- a/src/wayland-util.c<br>
+++ b/src/wayland-util.c<br>
@@ -167,22 +167,19 @@ wl_map_init(struct wl_map *map, uint32_t side)<br>
 WL_EXPORT void<br>
 wl_map_release(struct wl_map *map)<br>
 {<br>
-       wl_array_release(&map->client_entries);<br>
-       wl_array_release(&map->server_entries);<br>
+       wl_array_release(&map->entries);<br>
 }<br>
<br>
 WL_EXPORT uint32_t<br>
 wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data)<br>
 {<br>
        union map_entry *start, *entry;<br>
-       struct wl_array *entries;<br>
+       struct wl_array *entries = &map->entries;<br>
        uint32_t base;<br>
<br>
        if (map->side == WL_MAP_CLIENT_SIDE) {<br>
-               entries = &map->client_entries;<br>
                base = 0;<br>
        } else {<br>
-               entries = &map->server_entries;<br>
                base = WL_SERVER_ID_START;<br>
        }<br>
<br>
@@ -208,12 +205,9 @@ wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data)<br>
 {<br>
        union map_entry *start;<br>
        uint32_t count;<br>
-       struct wl_array *entries;<br>
+       struct wl_array *entries = &map->entries;<br>
<br>
-       if (i < WL_SERVER_ID_START) {<br>
-               entries = &map->client_entries;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
+       if (i >= WL_SERVER_ID_START) {<br>
                i -= WL_SERVER_ID_START;<br>
        }<br>
<br>
@@ -236,18 +230,14 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)<br>
 {<br>
        union map_entry *start;<br>
        uint32_t count;<br>
-       struct wl_array *entries;<br>
+       struct wl_array *entries = &map->entries;<br>
<br>
        if (i < WL_SERVER_ID_START) {<br>
                if (map->side == WL_MAP_CLIENT_SIDE)<br>
                        return -1;<br>
-<br>
-               entries = &map->client_entries;<br>
        } else {<br>
                if (map->side == WL_MAP_SERVER_SIDE)<br>
                        return -1;<br>
-<br>
-               entries = &map->server_entries;<br>
                i -= WL_SERVER_ID_START;<br>
        }<br>
<br>
@@ -274,18 +264,14 @@ WL_EXPORT void<br>
 wl_map_remove(struct wl_map *map, uint32_t i)<br>
 {<br>
        union map_entry *start;<br>
-       struct wl_array *entries;<br>
+       struct wl_array *entries = &map->entries;<br>
<br>
        if (i < WL_SERVER_ID_START) {<br>
                if (map->side == WL_MAP_SERVER_SIDE)<br>
                        return;<br>
-<br>
-               entries = &map->client_entries;<br>
        } else {<br>
                if (map->side == WL_MAP_CLIENT_SIDE)<br>
                        return;<br>
-<br>
-               entries = &map->server_entries;<br>
                i -= WL_SERVER_ID_START;<br>
        }<br>
<br>
@@ -299,12 +285,9 @@ wl_map_lookup(struct wl_map *map, uint32_t i)<br>
 {<br>
        union map_entry *start;<br>
        uint32_t count;<br>
-       struct wl_array *entries;<br>
+       struct wl_array *entries = &map->entries;<br>
<br>
-       if (i < WL_SERVER_ID_START) {<br>
-               entries = &map->client_entries;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
+       if (i >= WL_SERVER_ID_START) {<br>
                i -= WL_SERVER_ID_START;<br>
        }<br>
<br>
@@ -322,12 +305,9 @@ wl_map_lookup_flags(struct wl_map *map, uint32_t i)<br>
 {<br>
        union map_entry *start;<br>
        uint32_t count;<br>
-       struct wl_array *entries;<br>
+       struct wl_array *entries = &map->entries;<br>
<br>
-       if (i < WL_SERVER_ID_START) {<br>
-               entries = &map->client_entries;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
+       if (i >= WL_SERVER_ID_START) {<br>
                i -= WL_SERVER_ID_START;<br>
        }<br>
<br>
@@ -356,8 +336,7 @@ for_each_helper(struct wl_array *entries, wl_iterator_func_t func, void *data)<br>
 WL_EXPORT void<br>
 wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)<br>
 {<br>
-       for_each_helper(&map->client_entries, func, data);<br>
-       for_each_helper(&map->server_entries, func, data);<br>
+       for_each_helper(&map->entries, func, data);<br>
 }<br>
<br>
 static void<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.4<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>