Depsgraph: Use BLI::Set instead of std::unordered_set
Reviewers: sergey Differential Revision: https://developer.blender.org/D7506
This commit is contained in:
parent
ed32afd962
commit
69b6c89842
|
@ -28,7 +28,6 @@
|
|||
#include <cstring> /* required for STREQ later on. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
|
@ -122,8 +121,6 @@ extern "C" {
|
|||
|
||||
namespace DEG {
|
||||
|
||||
using std::unordered_set;
|
||||
|
||||
/* ***************** */
|
||||
/* Relations Builder */
|
||||
|
||||
|
@ -2762,7 +2759,7 @@ static bool is_reachable(const Node *const from, const Node *const to)
|
|||
// Perform a graph walk from 'to' towards its incoming connections.
|
||||
// Walking from 'from' towards its outgoing connections is 10x slower on the Spring rig.
|
||||
deque<const Node *> queue;
|
||||
unordered_set<const Node *> seen;
|
||||
Set<const Node *> seen;
|
||||
queue.push_back(to);
|
||||
while (!queue.empty()) {
|
||||
// Visit the next node to inspect.
|
||||
|
@ -2776,7 +2773,7 @@ static bool is_reachable(const Node *const from, const Node *const to)
|
|||
// Queue all incoming relations that we haven't seen before.
|
||||
for (Relation *relation : visit->inlinks) {
|
||||
const Node *prev_node = relation->from;
|
||||
if (seen.insert(prev_node).second) {
|
||||
if (seen.add(prev_node)) {
|
||||
queue.push_back(prev_node);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,14 +23,10 @@
|
|||
* Implementation of Querying and Filtering API's
|
||||
*/
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
extern "C" {
|
||||
#include "BLI_ghash.h"
|
||||
#include "BLI_utildefines.h"
|
||||
} /* extern "C" */
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
@ -50,8 +46,6 @@ extern "C" {
|
|||
namespace DEG {
|
||||
namespace {
|
||||
|
||||
using std::unordered_set;
|
||||
|
||||
typedef deque<OperationNode *> TraversalQueue;
|
||||
|
||||
typedef void (*DEGForeachOperation)(OperationNode *op_node, void *user_data);
|
||||
|
@ -80,7 +74,7 @@ void deg_foreach_dependent_operation(const Depsgraph *UNUSED(graph),
|
|||
}
|
||||
/* Start with scheduling all operations from ID node. */
|
||||
TraversalQueue queue;
|
||||
unordered_set<OperationNode *> scheduled;
|
||||
Set<OperationNode *> scheduled;
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, target_id_node->components) {
|
||||
if (source_component_type != DEG_OB_COMP_ANY &&
|
||||
nodeTypeToObjectComponent(comp_node->type) != source_component_type) {
|
||||
|
@ -91,7 +85,7 @@ void deg_foreach_dependent_operation(const Depsgraph *UNUSED(graph),
|
|||
continue;
|
||||
}
|
||||
queue.push_back(op_node);
|
||||
scheduled.insert(op_node);
|
||||
scheduled.add(op_node);
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
|
@ -105,9 +99,8 @@ void deg_foreach_dependent_operation(const Depsgraph *UNUSED(graph),
|
|||
/* Schedule outgoing operation nodes. */
|
||||
if (op_node->outlinks.size() == 1) {
|
||||
OperationNode *to_node = (OperationNode *)op_node->outlinks[0]->to;
|
||||
if (scheduled.find(to_node) == scheduled.end() &&
|
||||
deg_foreach_needs_visit(to_node, flags)) {
|
||||
scheduled.insert(to_node);
|
||||
if (!scheduled.contains(to_node) && deg_foreach_needs_visit(to_node, flags)) {
|
||||
scheduled.add_new(to_node);
|
||||
op_node = to_node;
|
||||
}
|
||||
else {
|
||||
|
@ -117,10 +110,9 @@ void deg_foreach_dependent_operation(const Depsgraph *UNUSED(graph),
|
|||
else {
|
||||
for (Relation *rel : op_node->outlinks) {
|
||||
OperationNode *to_node = (OperationNode *)rel->to;
|
||||
if (scheduled.find(to_node) == scheduled.end() &&
|
||||
deg_foreach_needs_visit(to_node, flags)) {
|
||||
if (!scheduled.contains(to_node) && deg_foreach_needs_visit(to_node, flags)) {
|
||||
queue.push_front(to_node);
|
||||
scheduled.insert(to_node);
|
||||
scheduled.add_new(to_node);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -133,7 +125,7 @@ struct ForeachIDComponentData {
|
|||
DEGForeachIDComponentCallback callback;
|
||||
void *user_data;
|
||||
IDNode *target_id_node;
|
||||
unordered_set<ComponentNode *> visited;
|
||||
Set<ComponentNode *> visited;
|
||||
};
|
||||
|
||||
void deg_foreach_dependent_component_callback(OperationNode *op_node, void *user_data_v)
|
||||
|
@ -141,11 +133,10 @@ void deg_foreach_dependent_component_callback(OperationNode *op_node, void *user
|
|||
ForeachIDComponentData *user_data = reinterpret_cast<ForeachIDComponentData *>(user_data_v);
|
||||
ComponentNode *comp_node = op_node->owner;
|
||||
IDNode *id_node = comp_node->owner;
|
||||
if (id_node != user_data->target_id_node &&
|
||||
user_data->visited.find(comp_node) == user_data->visited.end()) {
|
||||
if (id_node != user_data->target_id_node && !user_data->visited.contains(comp_node)) {
|
||||
user_data->callback(
|
||||
id_node->id_orig, nodeTypeToObjectComponent(comp_node->type), user_data->user_data);
|
||||
user_data->visited.insert(comp_node);
|
||||
user_data->visited.add_new(comp_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +163,7 @@ struct ForeachIDData {
|
|||
DEGForeachIDCallback callback;
|
||||
void *user_data;
|
||||
IDNode *target_id_node;
|
||||
unordered_set<IDNode *> visited;
|
||||
Set<IDNode *> visited;
|
||||
};
|
||||
|
||||
void deg_foreach_dependent_ID_callback(OperationNode *op_node, void *user_data_v)
|
||||
|
@ -180,10 +171,9 @@ void deg_foreach_dependent_ID_callback(OperationNode *op_node, void *user_data_v
|
|||
ForeachIDData *user_data = reinterpret_cast<ForeachIDData *>(user_data_v);
|
||||
ComponentNode *comp_node = op_node->owner;
|
||||
IDNode *id_node = comp_node->owner;
|
||||
if (id_node != user_data->target_id_node &&
|
||||
user_data->visited.find(id_node) == user_data->visited.end()) {
|
||||
if (id_node != user_data->target_id_node && !user_data->visited.contains(id_node)) {
|
||||
user_data->callback(id_node->id_orig, user_data->user_data);
|
||||
user_data->visited.insert(id_node);
|
||||
user_data->visited.add_new(id_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,16 +204,16 @@ void deg_foreach_ancestor_ID(const Depsgraph *graph,
|
|||
}
|
||||
/* Start with scheduling all operations from ID node. */
|
||||
TraversalQueue queue;
|
||||
unordered_set<OperationNode *> scheduled;
|
||||
Set<OperationNode *> scheduled;
|
||||
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, target_id_node->components) {
|
||||
for (OperationNode *op_node : comp_node->operations) {
|
||||
queue.push_back(op_node);
|
||||
scheduled.insert(op_node);
|
||||
scheduled.add(op_node);
|
||||
}
|
||||
}
|
||||
GHASH_FOREACH_END();
|
||||
unordered_set<IDNode *> visited;
|
||||
visited.insert(target_id_node);
|
||||
Set<IDNode *> visited;
|
||||
visited.add_new(target_id_node);
|
||||
/* Process the queue. */
|
||||
while (!queue.empty()) {
|
||||
/* get next operation node to process. */
|
||||
|
@ -233,18 +223,17 @@ void deg_foreach_ancestor_ID(const Depsgraph *graph,
|
|||
/* Check whether we need to inform callee about corresponding ID node. */
|
||||
ComponentNode *comp_node = op_node->owner;
|
||||
IDNode *id_node = comp_node->owner;
|
||||
if (visited.find(id_node) == visited.end()) {
|
||||
if (!visited.contains(id_node)) {
|
||||
/* TODO(sergey): Is it orig or CoW? */
|
||||
callback(id_node->id_orig, user_data);
|
||||
visited.insert(id_node);
|
||||
visited.add_new(id_node);
|
||||
}
|
||||
/* Schedule incoming operation nodes. */
|
||||
if (op_node->inlinks.size() == 1) {
|
||||
Node *from = op_node->inlinks[0]->from;
|
||||
if (from->get_class() == NodeClass::OPERATION) {
|
||||
OperationNode *from_node = (OperationNode *)from;
|
||||
if (scheduled.find(from_node) == scheduled.end()) {
|
||||
scheduled.insert(from_node);
|
||||
if (scheduled.add(from_node)) {
|
||||
op_node = from_node;
|
||||
}
|
||||
else {
|
||||
|
@ -257,9 +246,8 @@ void deg_foreach_ancestor_ID(const Depsgraph *graph,
|
|||
Node *from = rel->from;
|
||||
if (from->get_class() == NodeClass::OPERATION) {
|
||||
OperationNode *from_node = (OperationNode *)from;
|
||||
if (scheduled.find(from_node) == scheduled.end()) {
|
||||
if (scheduled.add(from_node)) {
|
||||
queue.push_front(from_node);
|
||||
scheduled.insert(from_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "BLI_set.hh"
|
||||
|
||||
struct Depsgraph;
|
||||
|
||||
struct CustomData_MeshMasks;
|
||||
|
@ -48,6 +50,7 @@ struct CustomData_MeshMasks;
|
|||
namespace DEG {
|
||||
|
||||
/* Commonly used types. */
|
||||
using BLI::Set;
|
||||
using std::deque;
|
||||
using std::map;
|
||||
using std::pair;
|
||||
|
|
Loading…
Reference in New Issue