1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

No caller checks the return code from Lst_Remove, so don't return one.

Simplify the algorithm now that circular lists are gone.
This commit is contained in:
Hartmut Brandt 2004-12-08 17:43:43 +00:00
parent 3b3c4bc949
commit c81703e6a4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=138577
2 changed files with 12 additions and 30 deletions

View File

@ -120,7 +120,7 @@ ReturnStatus Lst_Append(Lst *, LstNode *, void *);
/* Place an element at the end of a lst. */
#define Lst_AtEnd(LST, D) (Lst_Append((LST), Lst_Last(LST), (D)))
/* Remove an element */
ReturnStatus Lst_Remove(Lst *, LstNode *);
void Lst_Remove(Lst *, LstNode *);
/* Replace a node with a new value */
#define Lst_Replace(NODE, D) (((NODE) == NULL) ? FAILURE : \
(((NODE)->datum = (D)), SUCCESS))

View File

@ -64,42 +64,26 @@ __FBSDID("$FreeBSD$");
*
*-----------------------------------------------------------------------
*/
ReturnStatus
void
Lst_Remove(Lst *list, LstNode *ln)
{
if (!Lst_Valid(list) || !Lst_NodeValid(ln, list)) {
return (FAILURE);
}
/*
* unlink it from the list
*/
if (ln->nextPtr != NULL) {
if (ln->nextPtr != NULL)
/* unlink from the backward chain */
ln->nextPtr->prevPtr = ln->prevPtr;
}
if (ln->prevPtr != NULL) {
ln->prevPtr->nextPtr = ln->nextPtr;
}
/*
* if either the firstPtr or lastPtr of the list point to this node,
* adjust them accordingly
*/
if (list->firstPtr == ln) {
list->firstPtr = ln->nextPtr;
}
if (list->lastPtr == ln) {
else
/* this was the last element */
list->lastPtr = ln->prevPtr;
}
/*
* the only way firstPtr can still point to ln is if ln is the last
* node on the list. The list is, therefore, empty and is marked as such
*/
if (list->firstPtr == ln) {
list->firstPtr = NULL;
}
if (ln->prevPtr != NULL)
/* unlink from the forward chain */
ln->prevPtr->nextPtr = ln->nextPtr;
else
/* this was the first element */
list->firstPtr = ln->nextPtr;
/*
* note that the datum is unmolested. The caller must free it as
@ -110,6 +94,4 @@ Lst_Remove(Lst *list, LstNode *ln)
} else {
ln->flags |= LN_DELETED;
}
return (SUCCESS);
}