summaryrefslogtreecommitdiff
path: root/lib/llist.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2017-04-20 15:10:04 +0200
committerDaniel Stenberg <daniel@haxx.se>2017-04-22 11:25:27 +0200
commitcbae73e1dd95946597ea74ccb580c30f78e3fa73 (patch)
tree56697b9325403031bb2fcfc6a723719b9819b0be /lib/llist.c
parentcbb59ed9ce9555e0dc0b485247fe86f0e45006b3 (diff)
downloadcurl-cbae73e1dd95946597ea74ccb580c30f78e3fa73.tar.gz
llist: no longer uses malloc
The 'list element' struct now has to be within the data that is being added to the list. Removes 16.6% (tiny) mallocs from a simple HTTP transfer. (96 => 80) Also removed return codes since the llist functions can't fail now. Test 1300 updated accordingly. Closes #1435
Diffstat (limited to 'lib/llist.c')
-rw-r--r--lib/llist.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/lib/llist.c b/lib/llist.c
index b8836bbcc..15cac825a 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -49,18 +49,17 @@ Curl_llist_init(struct curl_llist *l, curl_llist_dtor dtor)
* entry is NULL and the list already has elements, the new one will be
* inserted first in the list.
*
+ * The 'ne' argument should be a pointer into the object to store.
+ *
* Returns: 1 on success and 0 on failure.
*
* @unittest: 1300
*/
-int
+void
Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
- const void *p)
+ const void *p,
+ struct curl_llist_element *ne)
{
- struct curl_llist_element *ne = malloc(sizeof(struct curl_llist_element));
- if(!ne)
- return 0;
-
ne->ptr = (void *) p;
if(list->size == 0) {
list->head = ne;
@@ -87,19 +86,18 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
}
++list->size;
-
- return 1;
}
/*
* @unittest: 1300
*/
-int
+void
Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
void *user)
{
+ void *ptr;
if(e == NULL || list->size == 0)
- return 1;
+ return;
if(e == list->head) {
list->head = e->next;
@@ -117,16 +115,16 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
e->next->prev = e->prev;
}
- list->dtor(user, e->ptr);
+ ptr = e->ptr;
e->ptr = NULL;
e->prev = NULL;
e->next = NULL;
- free(e);
--list->size;
- return 1;
+ /* call the dtor() last for when it actually frees the 'e' memory itself */
+ list->dtor(user, ptr);
}
void
@@ -147,13 +145,13 @@ Curl_llist_count(struct curl_llist *list)
/*
* @unittest: 1300
*/
-int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
- struct curl_llist *to_list,
- struct curl_llist_element *to_e)
+void Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
+ struct curl_llist *to_list,
+ struct curl_llist_element *to_e)
{
/* Remove element from list */
if(e == NULL || list->size == 0)
- return 0;
+ return;
if(e == list->head) {
list->head = e->next;
@@ -193,6 +191,4 @@ int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
}
++to_list->size;
-
- return 1;
}