From e279e8bb2a87e56d5356fc255d800516c8094cc5 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 17 May 2015 22:58:52 +0200 Subject: [PATCH] Fix param changed count logic, speed up logic for unused params --- src/modules/systemlib/param/param.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c index 6de03125ca..f2d5f81b16 100644 --- a/src/modules/systemlib/param/param.c +++ b/src/modules/systemlib/param/param.c @@ -338,20 +338,19 @@ param_get_index(param_t param) int param_get_used_index(param_t param) { - int param_storage_index = param_get_index(param); - - if (param_storage_index < 0) { + /* this tests for out of bounds and does a constant time lookup */ + if (!param_used(param)) { return -1; } - /* walk all params and count */ + /* walk all params and count, now knowing that it has a valid index */ int count = 0; - for (unsigned i = 0; i < (unsigned)param + 1; i++) { - for (unsigned j = 0; j < bits_per_allocation_unit; j++) { + for (unsigned i = 0; i < (unsigned)size_param_changed_storage_bytes; i++) { + for (unsigned j = 0; j < 8; j++) { if (param_changed_storage[i] & (1 << j)) { - if (param_storage_index == i) { + if ((unsigned)param == i * 8 + j) { return count; }