[linked-list] change PopAfter() parameter to be a pointer (#4599)

This commit changes `LinkedList::PopAfter()` method to accept a
pointer to a previous entry as a parameter. If the previous entry
pointer is NULL the entry at the head of the list is popped.
This commit is contained in:
Abtin Keshavarzian
2020-03-31 12:11:24 -07:00
committed by Jonathan Hui
parent 3560ed06f7
commit 8a5f538e6f
3 changed files with 29 additions and 28 deletions
+17 -7
View File
@@ -199,18 +199,28 @@ public:
*
* @note This method does not change the popped entry itself, i.e., the popped entry next pointer stays as before.
*
* @param[in] aPrevEntry A reference to n previous entry (the entry after this will be popped).
* @returns The entry that was popped if list is not empty, or NULL if there is no entry after the given one.
* @param[in] aPrevEntry A pointer to a previous entry. If it is not NULL the entry after this will be popped,
* otherwise (if it is NULL) the entry at head of the list is popped.
*
* @returns Pointer to the entry that was popped, or NULL if there is no entry to pop.
*
*/
Type *PopAfter(Type &aPrevEntry)
Type *PopAfter(Type *aPrevEntry)
{
Type *entry = aPrevEntry.GetNext();
Type *entry;
if (entry != NULL)
if (aPrevEntry == NULL)
{
aPrevEntry.SetNext(entry->GetNext());
entry = Pop();
}
else
{
entry = aPrevEntry->GetNext();
if (entry != NULL)
{
aPrevEntry->SetNext(entry->GetNext());
}
}
return entry;
+2 -18
View File
@@ -404,15 +404,7 @@ otError Netif::UnsubscribeExternalMulticast(const Address &aAddress)
VerifyOrExit((entry >= &mExtMulticastAddresses[0]) && (entry < OT_ARRAY_END(mExtMulticastAddresses)),
error = OT_ERROR_INVALID_ARGS);
if (last)
{
mMulticastAddresses.PopAfter(*last);
}
else
{
mMulticastAddresses.Pop();
}
mMulticastAddresses.PopAfter(last);
break;
}
@@ -528,15 +520,7 @@ otError Netif::RemoveExternalUnicastAddress(const Address &aAddress)
VerifyOrExit((entry >= &mExtUnicastAddresses[0]) && (entry < OT_ARRAY_END(mExtUnicastAddresses)),
error = OT_ERROR_INVALID_ARGS);
if (last)
{
mUnicastAddresses.PopAfter(*last);
}
else
{
mUnicastAddresses.Pop();
}
mUnicastAddresses.PopAfter(last);
break;
}
+10 -3
View File
@@ -132,13 +132,13 @@ void TestLinkedList(void)
list.Push(e);
VerifyLinkedListContent(&list, &e, &c, &a, &d, &b, NULL);
VerifyOrQuit(list.PopAfter(a) == &d, "LinkedList::PopAfter() failed");
VerifyOrQuit(list.PopAfter(&a) == &d, "LinkedList::PopAfter() failed");
VerifyLinkedListContent(&list, &e, &c, &a, &b, NULL);
VerifyOrQuit(list.PopAfter(b) == NULL, "LinkedList::PopAfter() failed");
VerifyOrQuit(list.PopAfter(&b) == NULL, "LinkedList::PopAfter() failed");
VerifyLinkedListContent(&list, &e, &c, &a, &b, NULL);
VerifyOrQuit(list.PopAfter(e) == &c, "LinkedList::PopAfter() failed");
VerifyOrQuit(list.PopAfter(&e) == &c, "LinkedList::PopAfter() failed");
VerifyLinkedListContent(&list, &e, &a, &b, NULL);
list.PushAfter(c, b);
@@ -147,8 +147,15 @@ void TestLinkedList(void)
list.PushAfter(d, a);
VerifyLinkedListContent(&list, &e, &a, &d, &b, &c, NULL);
VerifyOrQuit(list.PopAfter(NULL) == &e, "LinkedList::PopAfter() failed");
VerifyLinkedListContent(&list, &a, &d, &b, &c, NULL);
VerifyOrQuit(list.PopAfter(NULL) == &a, "LinkedList::PopAfter() failed");
VerifyLinkedListContent(&list, &d, &b, &c, NULL);
list.Clear();
VerifyOrQuit(list.IsEmpty(), "LinkedList::IsEmpty() failed after Clear()");
VerifyOrQuit(list.PopAfter(NULL) == NULL, "LinkedList::PopAfter() failed");
VerifyLinkedListContent(&list, NULL);
}