Bluetooth: GATT: Optimize static service handle resolution
This optimizes the lookups to skip ahead when attribute pointer is not located within service array. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
b62f2df5d4
commit
dde25a3d44
1 changed files with 7 additions and 0 deletions
|
@ -1278,6 +1278,13 @@ static uint16_t find_static_attr(const struct bt_gatt_attr *attr)
|
|||
uint16_t handle = 1;
|
||||
|
||||
Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) {
|
||||
/* Skip ahead if start is not within service attributes array */
|
||||
if ((attr < &static_svc->attrs[0]) ||
|
||||
(attr > &static_svc->attrs[static_svc->attr_count - 1])) {
|
||||
handle += static_svc->attr_count;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < static_svc->attr_count; i++, handle++) {
|
||||
if (attr == &static_svc->attrs[i]) {
|
||||
return handle;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue