Skip to content
Permalink
Browse files

Bluetooth: GATT: Skip ahead if handle is not within service handles

This reduces bt_gatt_foreach_attr complexity (O(n)) so it can skip
ahead when the start handle is not within its service handles.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information...
Vudentz authored and jhedberg committed Apr 2, 2019
1 parent 1a3d9fa commit 4154f27ab5a260f89e19ea5b700c4c1e169e29fc
Showing with 9 additions and 0 deletions.
  1. +9 −0 subsys/bluetooth/host/gatt.c
@@ -933,6 +933,15 @@ void bt_gatt_foreach_attr(u16_t start_handle, u16_t end_handle,

SYS_SLIST_FOR_EACH_CONTAINER(&db, svc, node) {
int i;
struct bt_gatt_service *next;

next = SYS_SLIST_PEEK_NEXT_CONTAINER(svc, node);
if (next) {
/* Skip ahead if start is not within service handles */
if (next->attrs[0].handle <= start_handle) {
continue;
}
}

for (i = 0; i < svc->attr_count; i++) {
struct bt_gatt_attr *attr = &svc->attrs[i];

0 comments on commit 4154f27

Please sign in to comment.
You can’t perform that action at this time.