loader: Optimize layer removal
authorMark Young <marky@lunarg.com>
Tue, 9 May 2017 21:23:33 +0000 (15:23 -0600)
committerMark Young <marky@lunarg.com>
Tue, 9 May 2017 22:33:05 +0000 (16:33 -0600)
In the case we remove a meta-layer, use memmove once, not in an
array.

Change-Id: Ia7496c4436e987011a0ad504a096c15f9d320c28

loader/loader.c

index 0e884c5..45af17e 100644 (file)
@@ -2028,14 +2028,14 @@ static void verify_all_meta_layers(const struct loader_instance *inst, struct lo
             // Delete the component layers
             loader_instance_heap_free(inst, prop->component_layer_names);
 
-            // Remove the current invalid meta-layer from the layer list
-            for (uint32_t j = i + 1; j < instance_layers->count; j++) {
-                // Use memmove since we are overlapping the source and destination addresses.
-                memmove(&instance_layers->list[j - 1], &instance_layers->list[j], sizeof(struct loader_layer_properties));
-            }
-            instance_layers->count--;
+            // Remove the current invalid meta-layer from the layer list.  Use memmove since we are
+            // overlapping the source and destination addresses.
+            memmove(&instance_layers->list[i], &instance_layers->list[i + 1],
+                    sizeof(struct loader_layer_properties) * (instance_layers->count - 1 - i));
 
-            // Decrement the loop index so we re-check this.
+            // Decrement the count (because we now have one less) and decrement the loop index since we need to
+            // re-check this index.
+            instance_layers->count--;
             i--;
         }
     }