types: steal types when merging if possible
authorRan Benita <ran234@gmail.com>
Sun, 9 Feb 2014 14:49:45 +0000 (16:49 +0200)
committerRan Benita <ran234@gmail.com>
Sun, 9 Feb 2014 14:49:45 +0000 (16:49 +0200)
Like we do everywhere else. Removes some unnecessary allocations and
copying.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/types.c

index f98d97a..b61ad55 100644 (file)
@@ -182,10 +182,16 @@ MergeIncludedKeyTypes(KeyTypesInfo *into, KeyTypesInfo *from,
         from->name = NULL;
     }
 
-    darray_foreach(type, from->types) {
-        type->merge = (merge == MERGE_DEFAULT ? type->merge : merge);
-        if (!AddKeyType(into, type, false))
-            into->errorCount++;
+    if (darray_empty(into->types)) {
+        into->types = from->types;
+        darray_init(from->types);
+    }
+    else {
+        darray_foreach(type, from->types) {
+            type->merge = (merge == MERGE_DEFAULT ? type->merge : merge);
+            if (!AddKeyType(into, type, false))
+                into->errorCount++;
+        }
     }
 }