Now that there are no users of Lst_ForEach and Lst_ForEachFrom are left
delete these two macros and all the associated stuff.
This commit is contained in:
parent
df4f9cb09a
commit
3d5967d365
@ -69,7 +69,6 @@ Lst_Append(Lst *list, LstNode *ln, void *d)
|
|||||||
|
|
||||||
nLNode = emalloc(sizeof(*nLNode));
|
nLNode = emalloc(sizeof(*nLNode));
|
||||||
nLNode->datum = d;
|
nLNode->datum = d;
|
||||||
nLNode->useCount = nLNode->flags = 0;
|
|
||||||
|
|
||||||
if (ln == NULL) {
|
if (ln == NULL) {
|
||||||
nLNode->nextPtr = nLNode->prevPtr = NULL;
|
nLNode->nextPtr = nLNode->prevPtr = NULL;
|
||||||
@ -161,7 +160,6 @@ Lst_Concat(Lst *list1, Lst *list2, int flags)
|
|||||||
list1->firstPtr = nln;
|
list1->firstPtr = nln;
|
||||||
}
|
}
|
||||||
nln->prevPtr = last;
|
nln->prevPtr = last;
|
||||||
nln->flags = nln->useCount = 0;
|
|
||||||
last = nln;
|
last = nln;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,62 +311,6 @@ Lst_FindFrom(Lst *l, LstNode *ln, const void *d, CompareProc *cProc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-
|
|
||||||
*-----------------------------------------------------------------------
|
|
||||||
* Lst_ForEachFrom --
|
|
||||||
* Apply the given function to each element of the given list. The
|
|
||||||
* function should return 0 if traversal should continue and non-
|
|
||||||
* zero if it should abort.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
* Side Effects:
|
|
||||||
* Only those created by the passed-in function.
|
|
||||||
*
|
|
||||||
*-----------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
Lst_ForEachFrom(Lst *list, LstNode *ln, DoProc *proc, void *d)
|
|
||||||
{
|
|
||||||
LstNode *next;
|
|
||||||
Boolean done;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
if (!Lst_Valid(list) || Lst_IsEmpty(list)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
/*
|
|
||||||
* Take care of having the current element deleted out from under
|
|
||||||
* us.
|
|
||||||
*/
|
|
||||||
|
|
||||||
next = ln->nextPtr;
|
|
||||||
|
|
||||||
ln->useCount++;
|
|
||||||
result = (*proc)(ln->datum, d);
|
|
||||||
ln->useCount--;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We're done with the traversal if
|
|
||||||
* - nothing's been added after the current node and
|
|
||||||
* - the next node to examine is the first in the queue or
|
|
||||||
* doesn't exist.
|
|
||||||
*/
|
|
||||||
done = (next == ln->nextPtr &&
|
|
||||||
(next == NULL || next == list->firstPtr));
|
|
||||||
|
|
||||||
next = ln->nextPtr;
|
|
||||||
|
|
||||||
if (ln->flags & LN_DELETED) {
|
|
||||||
free(ln);
|
|
||||||
}
|
|
||||||
ln = next;
|
|
||||||
} while (!result && !Lst_IsEmpty(list) && !done);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
*-----------------------------------------------------------------------
|
*-----------------------------------------------------------------------
|
||||||
* Lst_Insert --
|
* Lst_Insert --
|
||||||
@ -393,7 +335,6 @@ Lst_Insert(Lst *list, LstNode *ln, void *d)
|
|||||||
|
|
||||||
nLNode = emalloc(sizeof(*nLNode));
|
nLNode = emalloc(sizeof(*nLNode));
|
||||||
nLNode->datum = d;
|
nLNode->datum = d;
|
||||||
nLNode->useCount = nLNode->flags = 0;
|
|
||||||
|
|
||||||
if (ln == NULL) {
|
if (ln == NULL) {
|
||||||
nLNode->prevPtr = nLNode->nextPtr = NULL;
|
nLNode->prevPtr = nLNode->nextPtr = NULL;
|
||||||
@ -472,9 +413,5 @@ Lst_Remove(Lst *list, LstNode *ln)
|
|||||||
* note that the datum is unmolested. The caller must free it as
|
* note that the datum is unmolested. The caller must free it as
|
||||||
* necessary and as expected.
|
* necessary and as expected.
|
||||||
*/
|
*/
|
||||||
if (ln->useCount == 0) {
|
free(ln);
|
||||||
free(ln);
|
|
||||||
} else {
|
|
||||||
ln->flags |= LN_DELETED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -56,22 +56,10 @@
|
|||||||
struct LstNode {
|
struct LstNode {
|
||||||
struct LstNode *prevPtr; /* previous element in list */
|
struct LstNode *prevPtr; /* previous element in list */
|
||||||
struct LstNode *nextPtr; /* next in list */
|
struct LstNode *nextPtr; /* next in list */
|
||||||
int useCount:8; /* Count of functions using the node. Node may not
|
void *datum; /* datum associated with this element */
|
||||||
* be deleted until count goes to 0 */
|
|
||||||
int flags:8; /* Node status flags */
|
|
||||||
void *datum; /* datum associated with this element */
|
|
||||||
};
|
};
|
||||||
typedef struct LstNode LstNode;
|
typedef struct LstNode LstNode;
|
||||||
|
|
||||||
/*
|
|
||||||
* Flags required for synchronization
|
|
||||||
*/
|
|
||||||
#define LN_DELETED 0x0001 /* List node should be removed when done */
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
LstHead, LstMiddle, LstTail, LstUnknown
|
|
||||||
} LstWhere;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The list itself
|
* The list itself
|
||||||
*/
|
*/
|
||||||
@ -82,7 +70,6 @@ struct Lst {
|
|||||||
typedef struct Lst Lst;
|
typedef struct Lst Lst;
|
||||||
|
|
||||||
typedef int CompareProc(const void *, const void *);
|
typedef int CompareProc(const void *, const void *);
|
||||||
typedef int DoProc(void *, void *);
|
|
||||||
typedef void *DuplicateProc(void *);
|
typedef void *DuplicateProc(void *);
|
||||||
typedef void FreeProc(void *);
|
typedef void FreeProc(void *);
|
||||||
|
|
||||||
@ -159,21 +146,11 @@ LstNode *Lst_FindFrom(Lst *, LstNode *, const void *, CompareProc *);
|
|||||||
* the datum
|
* the datum
|
||||||
*/
|
*/
|
||||||
LstNode *Lst_Member(Lst *, void *);
|
LstNode *Lst_Member(Lst *, void *);
|
||||||
/* Apply a function to all elements of a lst */
|
|
||||||
void Lst_ForEach(Lst *, DoProc *, void *);
|
|
||||||
#define Lst_ForEach(LST, FN, D) (Lst_ForEachFrom((LST), Lst_First(LST), \
|
|
||||||
(FN), (D)))
|
|
||||||
|
|
||||||
|
/* Loop through a list. Note, that you may not delete the list element. */
|
||||||
#define LST_FOREACH(PTR, LST) \
|
#define LST_FOREACH(PTR, LST) \
|
||||||
for ((PTR) = (LST)->firstPtr; (PTR) != NULL; (PTR) = (PTR)->nextPtr)
|
for ((PTR) = (LST)->firstPtr; (PTR) != NULL; (PTR) = (PTR)->nextPtr)
|
||||||
|
|
||||||
/*
|
|
||||||
* Apply a function to all elements of a lst starting from a certain point.
|
|
||||||
* If the list is circular, the application will wrap around to the
|
|
||||||
* beginning of the list again.
|
|
||||||
*/
|
|
||||||
void Lst_ForEachFrom(Lst *, LstNode *, DoProc *, void *);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* for using the list as a queue
|
* for using the list as a queue
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user