pdch_ulc: Optimize rbtree FN search

Use logarithmic lookup algo to find if FN is available instead of
iterating over the whole tree.

Change-Id: I2843aedb5ce74c909bde82d29269d0f956e9a093
This commit is contained in:
Pau Espin 2021-03-29 11:29:22 +02:00
parent 54e6450293
commit 222f674116
1 changed files with 9 additions and 6 deletions

View File

@ -66,16 +66,19 @@ struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx)
struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn)
{
struct rb_node *node;
struct rb_node *node = ulc->tree_root.rb_node;
struct pdch_ulc_node *it;
int res;
for (node = rb_first(&ulc->tree_root); node; node = rb_next(node)) {
it = container_of(node, struct pdch_ulc_node, node);
while (node) {
it = rb_entry(node, struct pdch_ulc_node, node);
res = fn_cmp(it->fn, fn);
if (res == 0) /* it->fn == fn */
return it;
if (res > 0) /* it->fn AFTER fn */
break;
node = node->rb_left;
else if (res < 0) /* it->fn BEFORE fn */
node = node->rb_right;
else /* it->fn == fn */
return it;
}
return NULL;
}