kernel/util: Clean-ups to DoublyLinkedList insertion routines.
* Make some code common in Insert. * Remove unneeded logic from InsertAfter and just call the base Insert. InsertBefore does this, already. * Synchronize Insert code and APIs in the fs_shell DoublyLinkedList.
This commit is contained in:
@@ -327,8 +327,9 @@ public:
|
||||
|
||||
inline bool IsEmpty() const { return (fFirst == NULL); }
|
||||
|
||||
inline void Insert(Element *element, bool back = true);
|
||||
inline void Insert(Element *before, Element *element);
|
||||
inline void InsertBefore(Element* insertBefore, Element* element);
|
||||
inline void InsertAfter(Element* insertAfter, Element* element);
|
||||
inline void Insert(Element* element, bool back = true);
|
||||
inline void Add(Element *element, bool back = true);
|
||||
inline void Remove(Element *element);
|
||||
|
||||
@@ -361,6 +362,10 @@ public:
|
||||
inline ConstReverseIterator GetReverseIterator() const
|
||||
{ return ConstReverseIterator(this); }
|
||||
|
||||
private:
|
||||
inline void Insert(Element* before, Element* element);
|
||||
// TODO: Obsolete! Use InsertBefore() instead!
|
||||
|
||||
private:
|
||||
Element *fFirst;
|
||||
Element *fLast;
|
||||
@@ -401,10 +406,10 @@ DOUBLY_LINKED_LIST_CLASS_NAME::Insert(Element *element, bool back)
|
||||
}
|
||||
}
|
||||
|
||||
// Insert
|
||||
|
||||
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DOUBLY_LINKED_LIST_CLASS_NAME::Insert(Element *before, Element *element)
|
||||
DOUBLY_LINKED_LIST_CLASS_NAME::InsertBefore(Element* before, Element* element)
|
||||
{
|
||||
if (before == NULL) {
|
||||
Insert(element);
|
||||
@@ -426,6 +431,40 @@ DOUBLY_LINKED_LIST_CLASS_NAME::Insert(Element *before, Element *element)
|
||||
fFirst = element;
|
||||
}
|
||||
|
||||
|
||||
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DOUBLY_LINKED_LIST_CLASS_NAME::InsertAfter(Element* after, Element* element)
|
||||
{
|
||||
ASSERT(element != NULL);
|
||||
|
||||
if (after == NULL) {
|
||||
Insert(element, false);
|
||||
return;
|
||||
}
|
||||
|
||||
Link* afterLink = sGetLink(after);
|
||||
Link* link = sGetLink(element);
|
||||
|
||||
link->previous = after;
|
||||
link->next = afterLink->next;
|
||||
afterLink->next = element;
|
||||
|
||||
if (link->next != NULL)
|
||||
sGetLink(link->next)->previous = element;
|
||||
else
|
||||
fLast = element;
|
||||
}
|
||||
|
||||
|
||||
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DOUBLY_LINKED_LIST_CLASS_NAME::Insert(Element* before, Element* element)
|
||||
{
|
||||
InsertBefore(before, element);
|
||||
}
|
||||
|
||||
|
||||
// Add
|
||||
DOUBLY_LINKED_LIST_TEMPLATE_LIST
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user