diff options
author | David Benjamin <davidben@mit.edu> | 2013-08-20 10:15:28 -0400 |
---|---|---|
committer | David Benjamin <davidben@mit.edu> | 2013-08-20 10:15:28 -0400 |
commit | ddd7fbceb82784e2fa91a5c963f7ddf607eda2b6 (patch) | |
tree | ef4f3358ed18fb7da1800d8e1cdff75737857f91 | |
parent | a2c99aada00595e45f8f01d5f2b8ccabb85e6508 (diff) |
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.
-rw-r--r-- | lib/Zinternal.c | 54 |
1 files 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; } } |