From 019b24f16a70914f7bd53c07415eb279996e4bfd Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Wed, 29 Aug 2018 14:22:09 -0700 Subject: [PATCH] net: lwm2m: optimize lwm2m_perform_read_op() Optimize the resource processing loop to avoid extra assignments before checking if we need to process the actual resource. Signed-off-by: Michael Scott --- subsys/net/lib/lwm2m/lwm2m_engine.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 0b9d110ff55..793efb6c74f 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -2736,7 +2736,7 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj, struct lwm2m_output_context *out = context->out; struct lwm2m_obj_path *path = context->path; struct lwm2m_engine_obj_inst *obj_inst = NULL; - struct lwm2m_engine_res_inst *res; + struct lwm2m_engine_res_inst *res = NULL; struct lwm2m_engine_obj_field *obj_field; int ret = 0, index; u16_t temp_res_id, temp_len; @@ -2781,6 +2781,11 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj, temp_res_id = path->res_id; for (index = 0; index < obj_inst->resource_count; index++) { + if (path->level > 2 && + path->res_id != obj_inst->resources[index].res_id) { + continue; + } + res = &obj_inst->resources[index]; /* @@ -2788,12 +2793,7 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj, * res_id for lwm2m_read_handler to read this specific * resource. */ - if (path->level <= 2) { - path->res_id = res->res_id; - } else if (path->res_id != res->res_id) { - continue; - } - + path->res_id = res->res_id; obj_field = lwm2m_get_engine_obj_field(obj_inst->obj, res->res_id); if (!obj_field) {