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:
Luiz Augusto von Dentz 2020-09-03 13:17:49 -07:00 committed by Carles Cufí
commit dde25a3d44

View file

@ -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;