[PATCH] mi: streamline CopyGetMasterEvent(), remove code duplication.

Peter Hutterer peter.hutterer at who-t.net
Mon Dec 8 00:13:36 PST 2008


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 mi/mieq.c |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/mi/mieq.c b/mi/mieq.c
index 971edf9..f0eec26 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -277,25 +277,24 @@ void
 CopyGetMasterEvent(DeviceIntPtr mdev, xEvent* original,
                    xEvent** master, int count)
 {
-    if (count > 1) {
-        *master = xcalloc(count, sizeof(xEvent));
-        if (!*master)
-            FatalError("[mi] No memory left for master event.\n");
-        while(count--)
-        {
-            memcpy(&(*master)[count], &original[count], sizeof(xEvent));
-            ChangeDeviceID(mdev, &(*master)[count]);
-        }
-    } else
+    int len = count * sizeof(xEvent);
+    xEvent *ev;
+
+    /* Assumption: GenericEvents always have count 1 */
+
+    if (GEV(original)->type == GenericEvent)
+        len += GEV(original)->length * 4;
+
+    ev = xalloc(len);
+    if (!ev)
+        FatalError("[mi] No memory left for master event.\n");
+    memcpy(ev, original, len);
+    *master = ev;
+
+    while(count--)
     {
-        int len = sizeof(xEvent);
-        if (original->u.u.type == GenericEvent)
-            len += GEV(original)->length * 4;
-        *master = xalloc(len);
-        if (!*master)
-            FatalError("[mi] No memory left for master event.\n");
-        memcpy(*master, original, len);
-        ChangeDeviceID(mdev, *master);
+        ChangeDeviceID(mdev, ev);
+        ev++;
     }
 }
 
-- 
1.6.0.4




More information about the xorg mailing list