@@ -43,66 +43,56 @@ class IPreHashed : public IAsset
43
43
{
44
44
core::stack<IAsset*> stack;
45
45
core::unordered_set<IAsset*> alreadyVisited; // whether we have push the node to the stack
46
- core::unordered_set<IAsset*> alreadyDescended; // whether we have push the children to the stack
47
- auto push = [&stack,&alreadyVisited](IAsset* node) -> void
46
+ auto push = [&stack,&alreadyVisited](IAsset* node) -> bool
48
47
{
49
48
const auto [dummy,inserted] = alreadyVisited.insert (node);
50
49
if (inserted)
51
50
stack.push (node);
51
+ return true ;
52
52
};
53
53
for (const auto & root : roots)
54
54
push (root);
55
55
while (!stack.empty ())
56
56
{
57
57
auto * entry = stack.top ();
58
- const auto [dummy, inserted] = alreadyDescended.insert (entry);
59
- if (inserted)
60
- {
61
- core::unordered_set<IAsset*> dependants = entry->computeDependants ();
62
- for (auto * dependant : dependants) push (dependant);
63
- } else
64
- {
65
- // post order traversal does discard
66
- auto * isPrehashed = dynamic_cast <IPreHashed*>(entry);
67
- if (isPrehashed)
68
- isPrehashed->discardContent ();
69
- stack.pop ();
70
- }
58
+ stack.pop ();
59
+ entry->visitDependents (push);
60
+ // post order traversal does discard
61
+ auto * isPrehashed = dynamic_cast <IPreHashed*>(entry);
62
+ if (isPrehashed)
63
+ isPrehashed->discardContent ();
71
64
}
72
65
}
73
66
static inline bool anyDependantDiscardedContents (const IAsset* root)
74
67
{
75
68
core::stack<const IAsset*> stack;
76
69
core::unordered_set<const IAsset*> alreadyVisited; // whether we have push the node to the stack
77
- core::unordered_set< const IAsset*> alreadyDescended; // whether we have push the children to the stack
78
- auto push = [&stack,&alreadyVisited](const IAsset* node) -> bool
70
+ bool result = false ;
71
+ auto push = [&stack,&alreadyVisited,&result ](const IAsset* node) -> bool
79
72
{
80
- if (!node)
81
- return false ;
82
73
const auto [dummy,inserted] = alreadyVisited.insert (node);
83
74
if (inserted)
84
75
{
85
76
auto * isPrehashed = dynamic_cast <const IPreHashed*>(node);
86
77
if (isPrehashed && isPrehashed->missingContent ())
87
- return true ;
78
+ {
79
+ stack = {};
80
+ result = true ;
81
+ return false ;
82
+ }
88
83
stack.push (node);
89
84
}
90
- return false ;
85
+ return true ;
91
86
};
92
- if (push (root))
87
+ if (! push (root))
93
88
return true ;
94
89
while (!stack.empty ())
95
90
{
96
91
auto * entry = stack.top ();
97
- const auto [dummy, inserted] = alreadyDescended.insert (entry);
98
- if (inserted)
99
- {
100
- core::unordered_set<const IAsset*> dependants = entry->computeDependants ();
101
- for (auto * dependant : dependants) push (dependant);
102
- } else
103
- stack.pop ();
92
+ stack.pop ();
93
+ entry->visitDependents (push);
104
94
}
105
- return false ;
95
+ return result ;
106
96
}
107
97
108
98
protected:
0 commit comments