Skip to content

Commit cfbd633

Browse files
committedFeb 14, 2025
Make code for removal of list element cleaner
1 parent 1756691 commit cfbd633

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed
 

‎src/app/server-cluster/ServerClusterInterfaceRegistry.cpp

+12-25
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,24 @@ ServerClusterInterface * ServerClusterInterfaceRegistry::Unregister(const Concre
100100
VerifyOrReturnValue(endpointClusters != nullptr, nullptr);
101101
VerifyOrReturnValue(endpointClusters->firstCluster != nullptr, nullptr);
102102

103-
if (endpointClusters->firstCluster->GetClusterId() == path.mClusterId)
104-
{
105-
ServerClusterInterface * previous = endpointClusters->firstCluster;
106-
endpointClusters->firstCluster = endpointClusters->firstCluster->GetNextListItem();
107-
108-
if (endpointClusters->firstCluster == nullptr)
109-
{
110-
// Free up the endpoint as it has nothing on it.
111-
UnregisterAllFromEndpoint(endpointClusters->endpointId);
112-
}
113-
114-
if (mCachedInterface == previous)
115-
{
116-
mCachedClusterEndpointId = kInvalidEndpointId;
117-
mCachedInterface = nullptr;
118-
}
119-
previous->SetNotInList();
120-
121-
return previous;
122-
}
123-
124-
// not found, go through the underlying list and remove any found element
125-
ServerClusterInterface * prev = endpointClusters->firstCluster;
126-
ServerClusterInterface * current = endpointClusters->firstCluster->GetNextListItem();
103+
ServerClusterInterface * prev = nullptr;
104+
ServerClusterInterface * current = endpointClusters->firstCluster;
127105

128106
while (current != nullptr)
129107
{
130108
if (current->GetClusterId() == path.mClusterId)
131109
{
132110
// takes the item out of the current list and return it.
133-
prev->SetNextListItem(current->GetNextListItem());
111+
ServerClusterInterface * next = current->GetNextListItem();
112+
113+
if (prev == nullptr)
114+
{
115+
endpointClusters->firstCluster = next;
116+
}
117+
else
118+
{
119+
prev->SetNextListItem(next);
120+
}
134121

135122
if (mCachedInterface == current)
136123
{

0 commit comments

Comments
 (0)