Skip to content

Commit 877e667

Browse files
committed
LinkedList: Slight cleanup to _remove
Remove a little bit of duplication.
1 parent e83db1d commit 877e667

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/StringArray.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,16 @@ class LinkedList {
6060
};
6161

6262
void _remove(ItemType* pit, ItemType* it) {
63-
if(pit == nullptr){ // item is root
64-
_root = _root->next;
65-
if (_root == nullptr) {
66-
_last = nullptr;
67-
}
68-
} else {
69-
pit->next = it->next;
70-
if (it == _last) {
71-
_last = pit;
72-
}
73-
}
74-
75-
if (_onRemove) {
76-
_onRemove(it->value());
77-
}
78-
79-
delete it;
63+
auto* next = pit ? &pit->next : &_root;
64+
*next = it->next;
65+
if (_last == it) {
66+
_last = pit;
67+
}
68+
69+
if (_onRemove) {
70+
_onRemove(it->value());
71+
}
72+
delete it;
8073
}
8174

8275
public:

0 commit comments

Comments
 (0)