8000 list: optimize list_count by sreimers · Pull Request #1284 · baresip/re · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

list: optimize list_count #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/re_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ struct le {
struct list {
struct le *head; /**< First list element */
struct le *tail; /**< Last list element */
size_t cnt; /**< Number of elements */
};

/** Linked list Initializer */
#define LIST_INIT {NULL, NULL}
#define LIST_INIT {NULL, NULL, 0}


/**
Expand Down
20 changes: 10 additions & 10 deletions src/list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void list_init(struct list *list)

list->head = NULL;
list->tail = NULL;
list->cnt = 0;
}


Expand Down Expand Up @@ -109,6 +110,7 @@ void list_append(struct list *list, struct le *le, void *data)
list->tail->next = le;

list->tail = le;
++list->cnt;
}


Expand Down Expand Up @@ -141,6 +143,7 @@ void list_prepend(struct list *list, struct le *le, void *data)
list->tail = le;

list->head = le;
++list->cnt;
}


Expand Down Expand Up @@ -174,6 +177,7 @@ void list_insert_before(struct list *list, struct le *le, struct le *ile,
ile->data = data;

le->prev = ile;
++list->cnt;
}


Expand Down Expand Up @@ -207,6 +211,8 @@ void list_insert_after(struct list *list, struct le *le, struct le *ile,
ile->data = data;

le->next = ile;

++list->cnt;
}


Expand Down Expand Up @@ -271,6 +277,9 @@ void list_unlink(struct le *le)
le->next = NULL;
le->prev = NULL;
le->list = NULL;

if (list->cnt)
--list->cnt;
}


Expand Down Expand Up @@ -399,14 +408,5 @@ struct le *list_tail(const struct list *list)
*/
uint32_t list_count(const struct list *list)
{
uint32_t n = 0;
struct le *le;

if (!list)
return 0;

for (le = list->head; le; le = le->next)
++n;

return n;
return list ? (uint32_t)list->cnt : 0;
}
Loading
0