From b9fc19dbd6a4e5f2a079a5aa6a7efbcd1be4dedd Mon Sep 17 00:00:00 2001 From: Mark Young Date: Tue, 9 May 2017 15:23:33 -0600 Subject: loader: Optimize layer removal In the case we remove a meta-layer, use memmove once, not in an array. Change-Id: Ia7496c4436e987011a0ad504a096c15f9d320c28 --- loader/loader.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'loader') diff --git a/loader/loader.c b/loader/loader.c index 0e884c5d..45af17e4 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -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--; } } -- cgit v1.2.3