From ddd7fbceb82784e2fa91a5c963f7ddf607eda2b6 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Tue, 20 Aug 2013 10:15:28 -0400 Subject: Simplify Z_AddNoticeToEntry a bit The holelist isn't kept sorted; we used to always append to the end. But it's a singly-linked list, so prepending to it is going to be much much simpler. --- lib/Zinternal.c | 54 ++++++++++++++---------------------------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/lib/Zinternal.c b/lib/Zinternal.c index f6b727e..1f89df0 100644 --- a/lib/Zinternal.c +++ b/lib/Zinternal.c @@ -575,54 +575,28 @@ Z_AddNoticeToEntry(struct _Z_InputQ *qptr, qptr->holelist = hole->next; free((char *)hole); /* - * Now create a new hole that is the original hole without the - * current fragment. + * Now create new hole(s) that are the original hole without + * the current fragment. */ if (part > oldfirst) { - /* Search for the end of the hole list */ - hole = qptr->holelist; - lasthole = (struct _Z_Hole *) 0; - while (hole) { - lasthole = hole; - hole = hole->next; - } - if (lasthole) { - lasthole->next = (struct _Z_Hole *)malloc(sizeof(struct _Z_Hole)); - if (lasthole->next == NULL) - return ENOMEM; - hole = lasthole->next; - } else { - qptr->holelist = (struct _Z_Hole *)malloc(sizeof(struct _Z_Hole)); - if (qptr->holelist == NULL) - return ENOMEM; - hole = qptr->holelist; - } - hole->next = NULL; + hole = (struct _Z_Hole *)malloc(sizeof(struct _Z_Hole)); + if (hole == NULL) + return ENOMEM; hole->first = oldfirst; hole->last = part-1; + /* Prepend to the list; holelist is unordered. */ + hole->next = qptr->holelist; + qptr->holelist = hole; } if (last < oldlast) { - /* Search for the end of the hole list */ - hole = qptr->holelist; - lasthole = (struct _Z_Hole *) 0; - while (hole) { - lasthole = hole; - hole = hole->next; - } - if (lasthole) { - lasthole->next = (struct _Z_Hole *)malloc(sizeof(struct _Z_Hole)); - if (lasthole->next == NULL) - return ENOMEM; - hole = lasthole->next; - } else { - qptr->holelist = (struct _Z_Hole *)malloc(sizeof(struct _Z_Hole)); - if (qptr->holelist == NULL) - return ENOMEM; - hole = qptr->holelist; - } - hole->next = (struct _Z_Hole *) 0; + hole = (struct _Z_Hole *)malloc(sizeof(struct _Z_Hole)); + if (hole == NULL) + return ENOMEM; hole->first = last+1; hole->last = oldlast; + /* Prepend to the list; holelist is unordered. */ + hole->next = qptr->holelist; + qptr->holelist = hole; } } -- cgit v1.2.3