| 61 | } |
| 62 | |
| 63 | void destroy(String itemName = Slice::Empty) { |
| 64 | std::unordered_set<std::string> entries; |
| 65 | if (itemName.empty()) { |
| 66 | for (const auto& life : lives) { |
| 67 | entries.insert(life.first); |
| 68 | } |
| 69 | for (const auto& itemRef : itemRefs) { |
| 70 | entries.insert(itemRef.first); |
| 71 | } |
| 72 | for (auto& ref : refs) { |
| 73 | ref.visited = false; |
| 74 | auto entry = entries.find(ref.target); |
| 75 | if (entry != entries.end()) { |
| 76 | entries.erase(entry); |
| 77 | } |
| 78 | } |
| 79 | } else { |
| 80 | for (auto& ref : refs) { |
| 81 | ref.visited = false; |
| 82 | } |
| 83 | entries.insert(itemName.toString()); |
| 84 | } |
| 85 | for (const auto& entry : entries) { |
| 86 | std::vector<std::string> items; |
| 87 | std::queue<std::string> refList; |
| 88 | refList.push(entry); |
| 89 | while (!refList.empty()) { |
| 90 | std::string name = refList.front(); |
| 91 | refList.pop(); |
| 92 | items.push_back(name); |
| 93 | auto it = itemRefs.find(name); |
| 94 | if (it != itemRefs.end()) { |
| 95 | for (Reference* ref : *it->second) { |
| 96 | if (!ref->visited) { |
| 97 | ref->visited = true; |
| 98 | refList.push(ref->target); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | #if DORA_DEBUG |
| 104 | std::unordered_set<std::string> names; |
| 105 | std::vector<std::string> nameList; |
| 106 | for (auto it = items.rbegin(); it != items.rend(); ++it) { |
| 107 | if (names.find(*it) == names.end() && lives.find(*it) != lives.end()) { |
| 108 | names.insert(*it); |
| 109 | nameList.push_back(*it); |
| 110 | } |
| 111 | } |
| 112 | if (!nameList.empty()) { |
| 113 | LogInfo(fmt::format("destroy: {}.", std::accumulate(nameList.begin() + 1, nameList.end(), nameList.front(), [](const std::string& a, const std::string& b) { |
| 114 | return a + ", " + b; |
| 115 | }))); |
| 116 | } |
| 117 | #endif // DORA_DEBUG |
| 118 | for (auto it = items.rbegin(); it != items.rend(); ++it) { |
| 119 | lives.erase(*it); |
| 120 | itemRefs.erase(*it); |
no test coverage detected