summaryrefslogtreecommitdiffstats
path: root/src/state.h
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2016-11-15 01:13:16 (GMT)
committerJan Niklas Hasse <jhasse@bixense.com>2020-10-30 09:58:36 (GMT)
commit03cbfc65220e8f98548684e785d95bf5734c3f59 (patch)
treeb01c4024f41a1558374a9578b710770cca27412c /src/state.h
parentd45ff8ebf88ef4add46a80ccdfc2d97a8b4b091b (diff)
downloadNinja-03cbfc65220e8f98548684e785d95bf5734c3f59.zip
Ninja-03cbfc65220e8f98548684e785d95bf5734c3f59.tar.gz
Ninja-03cbfc65220e8f98548684e785d95bf5734c3f59.tar.bz2
Add unique IDs to edges
Edges are nominally ordered by order in the build manifest, but in fact are ordered by memory address. In most cases the memory address will be monontonically increasing. Since serialized build output will need unique IDs, add a monotonically increasing ID to edges, and use that for sorting instead of memory address.
Diffstat (limited to 'src/state.h')
-rw-r--r--src/state.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/state.h b/src/state.h
index f553ed4..72c5b33 100644
--- a/src/state.h
+++ b/src/state.h
@@ -21,6 +21,7 @@
#include <vector>
#include "eval_env.h"
+#include "graph.h"
#include "hash_map.h"
#include "util.h"
@@ -38,7 +39,7 @@ struct Rule;
/// completes).
struct Pool {
Pool(const std::string& name, int depth)
- : name_(name), current_use_(0), depth_(depth), delayed_(&WeightedEdgeCmp) {}
+ : name_(name), current_use_(0), depth_(depth), delayed_() {}
// A depth of 0 is infinite
bool is_valid() const { return depth_ >= 0; }
@@ -61,7 +62,7 @@ struct Pool {
void DelayEdge(Edge* edge);
/// Pool will add zero or more edges to the ready_queue
- void RetrieveReadyEdges(std::set<Edge*>* ready_queue);
+ void RetrieveReadyEdges(EdgeSet* ready_queue);
/// Dump the Pool and its edges (useful for debugging).
void Dump() const;
@@ -74,9 +75,16 @@ struct Pool {
int current_use_;
int depth_;
- static bool WeightedEdgeCmp(const Edge* a, const Edge* b);
+ struct WeightedEdgeCmp {
+ bool operator()(const Edge* a, const Edge* b) const {
+ if (!a) return b;
+ if (!b) return false;
+ int weight_diff = a->weight() - b->weight();
+ return ((weight_diff < 0) || (weight_diff == 0 && EdgeCmp()(a, b)));
+ }
+ };
- typedef std::set<Edge*,bool(*)(const Edge*, const Edge*)> DelayedEdges;
+ typedef std::set<Edge*, WeightedEdgeCmp> DelayedEdges;
DelayedEdges delayed_;
};