diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-11-15 18:35:23 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-11-15 18:35:23 +0000 |
commit | f3e8d59d5c584f5925a8b23919aaa5b5c954cf85 (patch) | |
tree | 8561cfc8a3317f4c2beb7d641ebd2c495149e2f4 /src | |
parent | c3b76c4171c1737a1d0066c8ec38062d7ba327e0 (diff) | |
download | mpd-f3e8d59d5c584f5925a8b23919aaa5b5c954cf85.tar.gz mpd-f3e8d59d5c584f5925a8b23919aaa5b5c954cf85.tar.xz mpd-f3e8d59d5c584f5925a8b23919aaa5b5c954cf85.zip |
use realloc for makeListNodesArray
git-svn-id: https://svn.musicpd.org/mpd/trunk@2676 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/list.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/list.c b/src/list.c index 45b19a93a..a777562d4 100644 --- a/src/list.c +++ b/src/list.c @@ -31,7 +31,8 @@ void makeListNodesArray(List * list) { if(!list->numberOfNodes) return; - list->nodesArray = malloc(sizeof(ListNode *)*list->numberOfNodes); + list->nodesArray = realloc(list->nodesArray, + sizeof(ListNode *)*list->numberOfNodes); for(i=0;i<list->numberOfNodes;i++) { list->nodesArray[i] = node; @@ -71,41 +72,40 @@ ListNode * insertInListBeforeNode(List * list, ListNode * beforeNode, char * node = malloc(sizeof(ListNode)); assert(node!=NULL); - if(beforeNode==NULL) node = insertInList(list, key, data); - else { - node->nextNode = beforeNode; - if(beforeNode==list->firstNode) { - if(list->firstNode==NULL) { - assert(list->lastNode==NULL); - list->lastNode = node; - } - else { - assert(list->lastNode!=NULL); - assert(list->lastNode->nextNode==NULL); - list->firstNode->prevNode = node; - } - node->prevNode = NULL; - list->firstNode = node; + node->nextNode = beforeNode; + if(beforeNode==list->firstNode) { + if(list->firstNode==NULL) { + assert(list->lastNode==NULL); + list->lastNode = node; } else { + assert(list->lastNode!=NULL); + assert(list->lastNode->nextNode==NULL); + list->firstNode->prevNode = node; + } + node->prevNode = NULL; + list->firstNode = node; + } + else { + if(beforeNode) { node->prevNode = beforeNode->prevNode; - if(node->prevNode) { - node->prevNode->nextNode = node; - } beforeNode->prevNode = node; } + else { + node->prevNode = list->lastNode; + list->lastNode = node; + } + node->prevNode->nextNode = node; + } - if(list->strdupKeys) node->key = strdup(key); - else node->key = key; + if(list->strdupKeys) node->key = strdup(key); + else node->key = key; - assert(node->key!=NULL); + node->data = data; - node->data = data; - - list->numberOfNodes++; - } + list->numberOfNodes++; - freeListNodesArray(list); + /*freeListNodesArray(list);*/ if(list->sorted) makeListNodesArray(list); return node; |