From 3c01127770b7d48a05ae0f506bee38dc911101f1 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sun, 5 Dec 2021 14:34:55 -0800 Subject: [PATCH] [srp-client] use `LinkedList::RemoveAllMatching()` (#7221) --- src/core/net/srp_client.cpp | 22 +--------------------- src/core/net/srp_client.hpp | 1 + 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/core/net/srp_client.cpp b/src/core/net/srp_client.cpp index d8d196098..a9022b462 100644 --- a/src/core/net/srp_client.cpp +++ b/src/core/net/srp_client.cpp @@ -1355,27 +1355,7 @@ void Client::HandleUpdateDone(void) void Client::GetRemovedServices(LinkedList &aRemovedServices) { - Service *service; - Service *prev; - Service *next; - - for (prev = nullptr, service = mServices.GetHead(); service != nullptr; service = next) - { - next = service->GetNext(); - - if (service->GetState() == kRemoved) - { - mServices.PopAfter(prev); - aRemovedServices.Push(*service); - - // When the service is removed from the list - // we keep the `prev` pointer same as before. - } - else - { - prev = service; - } - } + mServices.RemoveAllMatching(kRemoved, aRemovedServices); } Error Client::ReadResourceRecord(const Message &aMessage, uint16_t &aOffset, Dns::ResourceRecord &aRecord) diff --git a/src/core/net/srp_client.hpp b/src/core/net/srp_client.hpp index 3e0794d73..923abe658 100644 --- a/src/core/net/srp_client.hpp +++ b/src/core/net/srp_client.hpp @@ -267,6 +267,7 @@ public: TimeMilli GetLeaseRenewTime(void) const { return TimeMilli(mData); } void SetLeaseRenewTime(TimeMilli aTime) { mData = aTime.GetValue(); } bool Matches(const Service &aOther) const; + bool Matches(ItemState aState) const { return GetState() == aState; } }; /**