Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/cppgc_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ namespace node {

void CppgcWrapperList::Cleanup() {
for (auto node : *this) {
CppgcMixin* ptr = node->persistent.Get();
if (ptr != nullptr) {
if (auto* ptr = node->persistent.Get()) {
ptr->Finalize();
}
}
}

void CppgcWrapperList::MemoryInfo(MemoryTracker* tracker) const {
for (auto node : *this) {
CppgcMixin* ptr = node->persistent.Get();
if (ptr != nullptr) {
if (auto* ptr = node->persistent.Get()) {
// TODO(addaleax): Add weak edges instead of no edges once
// https://github.com/v8/v8/commit/e37cadf1143a8c5bbe44c0408186b5a26cc23863
// is available for us
Expand All @@ -25,16 +23,16 @@ void CppgcWrapperList::MemoryInfo(MemoryTracker* tracker) const {
}

void CppgcWrapperList::PurgeEmpty() {
for (auto weak_it = begin(); weak_it != end();) {
CppgcWrapperListNode* node = *weak_it;
auto next_it = ++weak_it;
for (auto it = begin(); it != end(); ) {
CppgcWrapperListNode* node = *it;
++it; // Advance the iterator BEFORE deletion to avoid dangling references

// The underlying cppgc wrapper has already been garbage collected.
// Remove it from the list.
if (!node->persistent) {
node->persistent.Clear();
delete node;
delete node;
}
weak_it = next_it;
}
}

} // namespace node
Loading