about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTList.c
diff options
context:
space:
mode:
Diffstat (limited to 'WWW/Library/Implementation/HTList.c')
-rw-r--r--WWW/Library/Implementation/HTList.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/WWW/Library/Implementation/HTList.c b/WWW/Library/Implementation/HTList.c
index cc46beda..7a856833 100644
--- a/WWW/Library/Implementation/HTList.c
+++ b/WWW/Library/Implementation/HTList.c
@@ -87,6 +87,31 @@ PUBLIC HTList * HTList_appendList ARGS2(
 }
 
 
+/*	Link object to START of list (so it is pointed to by the head).
+ *
+ *	Unlike HTList_addObject(), it does not malloc memory for HTList entry,
+ *	it use already allocated memory which should not be free'd by any
+ *	list operations (optimization).
+ */
+PUBLIC void HTList_linkObject ARGS3(
+	HTList *,	me,
+	void *,		newObject,
+	HTList *,	newNode)
+{
+    if (me) {
+	newNode->object = newObject;
+	newNode->next = me->next;
+	me->next = newNode;
+
+    } else {
+	CTRACE((tfp, "HTList: Trying to link object %p to a nonexisting list\n",
+		    newObject));
+    }
+
+    return;
+}
+
+
 /*      Add object to START of list (so it is pointed to by the head).
 */
 PUBLIC void HTList_addObject ARGS2(
@@ -175,6 +200,30 @@ PUBLIC void HTList_insertObjectAt ARGS3(
 }
 
 
+/*	Unlink specified object from list.
+ *	It does not free memory.
+ */
+PUBLIC BOOL HTList_unlinkObject ARGS2(
+	HTList *,	me,
+	void *,		oldObject)
+{
+    HTList *temp = me;
+    HTList *prevNode;
+
+    if (temp && oldObject) {
+	while (temp->next) {
+	    prevNode = temp;
+	    temp = temp->next;
+	    if (temp->object == oldObject) {
+		prevNode->next = temp->next;
+		return YES;  /* Success */
+	    }
+	}
+    }
+    return NO;  /* object not found or NULL list */
+}
+
+
 /*	Remove specified object from list.
 */
 PUBLIC BOOL HTList_removeObject ARGS2(
@@ -230,6 +279,27 @@ PUBLIC void * HTList_removeObjectAt  ARGS2(
     return NULL;  /* Reached the end of the list */
 }
 
+/*	Unlink object from START of list (the Last one inserted
+ *	via HTList_linkObject(), and pointed to by the head).
+ *	It does not free memory.
+ */
+PUBLIC void * HTList_unlinkLastObject ARGS1(
+	HTList *,	me)
+{
+    HTList * lastNode;
+    void * lastObject;
+
+    if (me && me->next) {
+	lastNode = me->next;
+	lastObject = lastNode->object;
+	me->next = lastNode->next;
+	return lastObject;
+
+    } else {  /* Empty list */
+	return NULL;
+    }
+}
+
 
 /*	Remove object from START of list (the Last one inserted
 **	via HTList_addObject(), and pointed to by the head).