Depsgraph: Fully switch from string to const char*

This brings up to 10-20% depsgraph build time improvement in the layout
files from the studio repository.
This commit is contained in:
Sergey Sharybin 2016-11-03 14:45:47 +01:00
parent 570c072020
commit 06c202002b
13 changed files with 85 additions and 79 deletions

View File

@ -190,7 +190,7 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag)
{
OperationDepsNode *op_node = comp_node->has_operation(opcode,
@ -218,7 +218,7 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag)
{
ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
@ -231,7 +231,7 @@ OperationDepsNode *DepsgraphNodeBuilder::add_operation_node(
eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string& name,
const char *name,
int name_tag)
{
return add_operation_node(id,
@ -248,7 +248,7 @@ bool DepsgraphNodeBuilder::has_operation_node(ID *id,
eDepsNode_Type comp_type,
const char *comp_name,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag)
{
return find_operation_node(id,
@ -264,7 +264,7 @@ OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
eDepsNode_Type comp_type,
const char *comp_name,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag)
{
ComponentDepsNode *comp_node = add_component_node(id, comp_type, comp_name);
@ -275,7 +275,7 @@ OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
ID *id,
eDepsNode_Type comp_type,
eDepsOperation_Code opcode,
const string& name,
const char *name,
int name_tag)
{
return find_operation_node(id, comp_type, "", opcode, name, name_tag);

View File

@ -82,7 +82,7 @@ struct DepsgraphNodeBuilder {
eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string& name = "",
const char *name = "",
int name_tag = -1);
OperationDepsNode *add_operation_node(ID *id,
eDepsNode_Type comp_type,
@ -90,34 +90,34 @@ struct DepsgraphNodeBuilder {
eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string& name = "",
const char *name = "",
int name_tag = -1);
OperationDepsNode *add_operation_node(ID *id,
eDepsNode_Type comp_type,
eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string& name = "",
const char *name = "",
int name_tag = -1);
bool has_operation_node(ID *id,
eDepsNode_Type comp_type,
const char *comp_name,
eDepsOperation_Code opcode,
const string& name = "",
const char *name = "",
int name_tag = -1);
OperationDepsNode *find_operation_node(ID *id,
eDepsNode_Type comp_type,
const char *comp_name,
eDepsOperation_Code opcode,
const string &name = "",
const char *name = "",
int name_tag = -1);
OperationDepsNode *find_operation_node(ID *id,
eDepsNode_Type comp_type,
eDepsOperation_Code opcode,
const string &name = "",
const char *name = "",
int name_tag = -1);
void build_scene(Main *bmain, Scene *scene);

View File

@ -214,7 +214,7 @@ OperationDepsNode *DepsgraphRelationBuilder::find_node(
key.name_tag);
if (!op_node) {
fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
DEG_OPNAMES[key.opcode], key.name.c_str());
DEG_OPNAMES[key.opcode], key.name);
}
return op_node;
}

View File

@ -104,7 +104,7 @@ struct ComponentKey
ComponentKey() :
id(NULL), type(DEPSNODE_TYPE_UNDEFINED), name("")
{}
ComponentKey(ID *id, eDepsNode_Type type, const string &name = "") :
ComponentKey(ID *id, eDepsNode_Type type, const char *name = "") :
id(id), type(type), name(name)
{}
@ -120,7 +120,7 @@ struct ComponentKey
ID *id;
eDepsNode_Type type;
string name;
const char *name;
};
struct OperationKey
@ -136,7 +136,7 @@ struct OperationKey
OperationKey(ID *id,
eDepsNode_Type component_type,
const string &name,
const char *name,
int name_tag = -1)
: id(id),
component_type(component_type),
@ -147,8 +147,8 @@ struct OperationKey
{}
OperationKey(ID *id,
eDepsNode_Type component_type,
const string &component_name,
const string &name,
const char *component_name,
const char *name,
int name_tag)
: id(id),
component_type(component_type),
@ -170,7 +170,7 @@ struct OperationKey
{}
OperationKey(ID *id,
eDepsNode_Type component_type,
const string &component_name,
const char *component_name,
eDepsOperation_Code opcode)
: id(id),
component_type(component_type),
@ -183,7 +183,7 @@ struct OperationKey
OperationKey(ID *id,
eDepsNode_Type component_type,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag = -1)
: id(id),
component_type(component_type),
@ -194,9 +194,9 @@ struct OperationKey
{}
OperationKey(ID *id,
eDepsNode_Type component_type,
const string &component_name,
const char *component_name,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag = -1)
: id(id),
component_type(component_type),
@ -217,9 +217,9 @@ struct OperationKey
ID *id;
eDepsNode_Type component_type;
string component_name;
const char *component_name;
eDepsOperation_Code opcode;
string name;
const char *name;
int name_tag;
};
@ -327,7 +327,7 @@ protected:
template <typename KeyType>
DepsNodeHandle create_node_handle(const KeyType& key,
const string& default_name = "");
const char *default_name = "");
bool needs_animdata_node(ID *id);
@ -337,7 +337,7 @@ private:
struct DepsNodeHandle
{
DepsNodeHandle(DepsgraphRelationBuilder *builder, OperationDepsNode *node, const string &default_name = "") :
DepsNodeHandle(DepsgraphRelationBuilder *builder, OperationDepsNode *node, const char *default_name = "") :
builder(builder),
node(node),
default_name(default_name)
@ -347,7 +347,7 @@ struct DepsNodeHandle
DepsgraphRelationBuilder *builder;
OperationDepsNode *node;
const string &default_name;
const char *default_name;
};
/* Utilities for Builders ----------------------------------------------------- */
@ -441,7 +441,7 @@ void DepsgraphRelationBuilder::add_node_handle_relation(
template <typename KeyType>
DepsNodeHandle DepsgraphRelationBuilder::create_node_handle(
const KeyType &key,
const string &default_name)
const char *default_name)
{
return DepsNodeHandle(this, find_node(key), default_name);
}

View File

@ -321,7 +321,7 @@ static void deg_debug_graphviz_node_single(const DebugContext &ctx,
static void deg_debug_graphviz_node_cluster_begin(const DebugContext &ctx,
const DepsNode *node)
{
string name = node->identifier().c_str();
string name = node->identifier();
if (node->type == DEPSNODE_TYPE_ID_REF) {
IDDepsNode *id_node = (IDDepsNode *)node;
char buf[256];

View File

@ -63,8 +63,8 @@ struct DepsNodeFactory {
virtual const char *tname() const = 0;
virtual DepsNode *create_node(const ID *id,
const string &subdata,
const string &name) const = 0;
const char *subdata,
const char *name) const = 0;
};
template <class NodeType>
@ -73,7 +73,7 @@ struct DepsNodeFactoryImpl : public DepsNodeFactory {
eDepsNode_Class tclass() const { return NodeType::typeinfo.tclass; }
const char *tname() const { return NodeType::typeinfo.tname; }
DepsNode *create_node(const ID *id, const string &subdata, const string &name) const
DepsNode *create_node(const ID *id, const char *subdata, const char *name) const
{
DepsNode *node = OBJECT_GUARDED_NEW(NodeType);
@ -81,12 +81,14 @@ struct DepsNodeFactoryImpl : public DepsNodeFactory {
node->type = type();
node->tclass = tclass();
if (!name.empty())
if (name[0] != '\0') {
/* set name if provided ... */
node->name = name;
else
}
else {
/* ... otherwise use default type name */
node->name = tname();
}
node->init(id, subdata);

View File

@ -51,10 +51,10 @@ namespace DEG {
DepsgraphStats *DepsgraphDebug::stats = NULL;
static string get_component_name(eDepsNode_Type type, const string &name = "")
static string get_component_name(eDepsNode_Type type, const char *name = "")
{
DepsNodeFactory *factory = deg_get_node_factory(type);
if (name.empty()) {
if (name[0] != '\0') {
return string(factory->tname());
}
else {
@ -114,7 +114,7 @@ void DepsgraphDebug::task_started(Depsgraph *graph,
*/
DepsgraphStatsComponent *comp_stats =
get_component_stats(id, get_component_name(comp->type,
comp->name),
comp->name).c_str(),
true);
times_clear(comp_stats->times);
}
@ -144,7 +144,7 @@ void DepsgraphDebug::task_completed(Depsgraph *graph,
DepsgraphStatsComponent *comp_stats =
get_component_stats(id,
get_component_name(comp->type,
comp->name),
comp->name).c_str(),
true);
times_add(comp_stats->times, time);
}
@ -224,7 +224,7 @@ DepsgraphStatsID *DepsgraphDebug::get_id_stats(ID *id, bool create)
DepsgraphStatsComponent *DepsgraphDebug::get_component_stats(
DepsgraphStatsID *id_stats,
const string &name,
const char *name,
bool create)
{
DepsgraphStatsComponent *comp_stats;
@ -232,13 +232,14 @@ DepsgraphStatsComponent *DepsgraphDebug::get_component_stats(
comp_stats != NULL;
comp_stats = comp_stats->next)
{
if (STREQ(comp_stats->name, name.c_str()))
if (STREQ(comp_stats->name, name)) {
break;
}
}
if (!comp_stats && create) {
comp_stats = (DepsgraphStatsComponent *)MEM_callocN(sizeof(DepsgraphStatsComponent),
"Depsgraph Component Stats");
BLI_strncpy(comp_stats->name, name.c_str(), sizeof(comp_stats->name));
BLI_strncpy(comp_stats->name, name, sizeof(comp_stats->name));
BLI_addtail(&id_stats->components, comp_stats);
}
return comp_stats;

View File

@ -66,10 +66,10 @@ struct DepsgraphDebug {
static DepsgraphStatsID *get_id_stats(ID *id, bool create);
static DepsgraphStatsComponent *get_component_stats(DepsgraphStatsID *id_stats,
const string &name,
const char *name,
bool create);
static DepsgraphStatsComponent *get_component_stats(ID *id,
const string &name,
const char *name,
bool create)
{
return get_component_stats(get_id_stats(id, create), name, create);

View File

@ -71,7 +71,7 @@ DepsNode::TypeInfo::TypeInfo(eDepsNode_Type type, const char *tname)
DepsNode::DepsNode()
{
name[0] = '\0';
name = "";
}
DepsNode::~DepsNode()
@ -121,7 +121,7 @@ RootDepsNode::~RootDepsNode()
OBJECT_GUARDED_DELETE(time_source, TimeSourceDepsNode);
}
TimeSourceDepsNode *RootDepsNode::add_time_source(const string &name)
TimeSourceDepsNode *RootDepsNode::add_time_source(const char *name)
{
if (!time_source) {
DepsNodeFactory *factory = deg_get_node_factory(DEPSNODE_TYPE_TIMESOURCE);
@ -146,7 +146,7 @@ static unsigned int id_deps_node_hash_key(const void *key_v)
const IDDepsNode::ComponentIDKey *key =
reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v);
return hash_combine(BLI_ghashutil_uinthash(key->type),
BLI_ghashutil_strhash_p(key->name.c_str()));
BLI_ghashutil_strhash_p(key->name));
}
static bool id_deps_node_hash_key_cmp(const void *a, const void *b)
@ -172,7 +172,7 @@ static void id_deps_node_hash_value_free(void *value_v)
}
/* Initialize 'id' node - from pointer data given. */
void IDDepsNode::init(const ID *id, const string &UNUSED(subdata))
void IDDepsNode::init(const ID *id, const char *UNUSED(subdata))
{
/* Store ID-pointer. */
BLI_assert(id != NULL);
@ -203,14 +203,14 @@ IDDepsNode::~IDDepsNode()
}
ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type,
const string &name) const
const char *name) const
{
ComponentIDKey key(type, name);
return reinterpret_cast<ComponentDepsNode *>(BLI_ghash_lookup(components, &key));
}
ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type,
const string &name)
const char *name)
{
ComponentDepsNode *comp_node = find_component(type, name);
if (!comp_node) {
@ -225,7 +225,7 @@ ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type,
return comp_node;
}
void IDDepsNode::remove_component(eDepsNode_Type type, const string &name)
void IDDepsNode::remove_component(eDepsNode_Type type, const char *name)
{
ComponentDepsNode *comp_node = find_component(type, name);
if (comp_node) {
@ -280,7 +280,7 @@ static DepsNodeFactoryImpl<IDDepsNode> DNTI_ID_REF;
/* Subgraph Node ========================================== */
/* Initialize 'subgraph' node - from pointer data given. */
void SubgraphDepsNode::init(const ID *id, const string &UNUSED(subdata))
void SubgraphDepsNode::init(const ID *id, const char *UNUSED(subdata))
{
/* Store ID-ref if provided. */
this->root_id = (ID *)id;

View File

@ -32,6 +32,8 @@
#include "intern/depsgraph_types.h"
#include "BLI_utildefines.h"
struct ID;
struct GHash;
struct Scene;
@ -57,7 +59,7 @@ struct DepsNode {
};
/* Identifier - mainly for debugging purposes. */
string name;
const char *name;
/* Structural type of node. */
eDepsNode_Type type;
@ -90,7 +92,7 @@ struct DepsNode {
string full_identifier() const;
virtual void init(const ID * /*id*/,
const string &/*subdata*/) {}
const char * /*subdata*/) {}
virtual void tag_update(Depsgraph * /*graph*/) {}
@ -129,7 +131,7 @@ struct RootDepsNode : public DepsNode {
RootDepsNode();
~RootDepsNode();
TimeSourceDepsNode *add_time_source(const string &name = "");
TimeSourceDepsNode *add_time_source(const char *name = "");
/* scene that this corresponds to */
Scene *scene;
@ -143,26 +145,27 @@ struct RootDepsNode : public DepsNode {
/* ID-Block Reference */
struct IDDepsNode : public DepsNode {
struct ComponentIDKey {
ComponentIDKey(eDepsNode_Type type, const string &name = "")
ComponentIDKey(eDepsNode_Type type, const char *name = "")
: type(type), name(name) {}
bool operator== (const ComponentIDKey &other) const
{
return type == other.type && name == other.name;
return type == other.type &&
STREQ(name, other.name);
}
eDepsNode_Type type;
string name;
const char *name;
};
void init(const ID *id, const string &subdata);
void init(const ID *id, const char *subdata);
~IDDepsNode();
ComponentDepsNode *find_component(eDepsNode_Type type,
const string &name = "") const;
const char *name = "") const;
ComponentDepsNode *add_component(eDepsNode_Type type,
const string &name = "");
void remove_component(eDepsNode_Type type, const string &name = "");
const char *name = "");
void remove_component(eDepsNode_Type type, const char *name = "");
void clear_components();
void tag_update(Depsgraph *graph);
@ -189,7 +192,7 @@ struct IDDepsNode : public DepsNode {
/* Subgraph Reference. */
struct SubgraphDepsNode : public DepsNode {
void init(const ID *id, const string &subdata);
void init(const ID *id, const char *subdata);
~SubgraphDepsNode();
/* Instanced graph. */

View File

@ -57,7 +57,7 @@ static unsigned int comp_node_hash_key(const void *key_v)
const ComponentDepsNode::OperationIDKey *key =
reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(key_v);
return hash_combine(BLI_ghashutil_uinthash(key->opcode),
BLI_ghashutil_strhash_p(key->name.c_str()));
BLI_ghashutil_strhash_p(key->name));
}
static bool comp_node_hash_key_cmp(const void *a, const void *b)
@ -94,7 +94,7 @@ ComponentDepsNode::ComponentDepsNode() :
/* Initialize 'component' node - from pointer data given */
void ComponentDepsNode::init(const ID * /*id*/,
const string & /*subdata*/)
const char * /*subdata*/)
{
/* hook up eval context? */
// XXX: maybe this needs a special API?
@ -113,7 +113,7 @@ ComponentDepsNode::~ComponentDepsNode()
string ComponentDepsNode::identifier() const
{
string &idname = this->owner->name;
string idname = this->owner->name;
char typebuf[16];
sprintf(typebuf, "(%d)", type);
@ -139,7 +139,7 @@ OperationDepsNode *ComponentDepsNode::find_operation(OperationIDKey key) const
}
OperationDepsNode *ComponentDepsNode::find_operation(eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag) const
{
OperationIDKey key(opcode, name, name_tag);
@ -152,7 +152,7 @@ OperationDepsNode *ComponentDepsNode::has_operation(OperationIDKey key) const
}
OperationDepsNode *ComponentDepsNode::has_operation(eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag) const
{
OperationIDKey key(opcode, name, name_tag);
@ -162,7 +162,7 @@ OperationDepsNode *ComponentDepsNode::has_operation(eDepsOperation_Code opcode,
OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag)
{
OperationDepsNode *op_node = has_operation(opcode, name, name_tag);
@ -333,7 +333,7 @@ static DepsNodeFactoryImpl<PoseComponentDepsNode> DNTI_EVAL_POSE;
/* Bone Component ========================================= */
/* Initialize 'bone component' node - from pointer data given */
void BoneComponentDepsNode::init(const ID *id, const string &subdata)
void BoneComponentDepsNode::init(const ID *id, const char *subdata)
{
/* generic component-node... */
ComponentDepsNode::init(id, subdata);
@ -346,7 +346,7 @@ void BoneComponentDepsNode::init(const ID *id, const string &subdata)
/* bone-specific node data */
Object *ob = (Object *)id;
this->pchan = BKE_pose_channel_find_name(ob->pose, subdata.c_str());
this->pchan = BKE_pose_channel_find_name(ob->pose, subdata);
}
DEG_DEPSNODE_DEFINE(BoneComponentDepsNode, DEPSNODE_TYPE_BONE, "Bone Component");

View File

@ -53,7 +53,7 @@ struct ComponentDepsNode : public DepsNode {
struct OperationIDKey
{
eDepsOperation_Code opcode;
string name;
const char *name;
int name_tag;
OperationIDKey()
@ -67,7 +67,7 @@ struct ComponentDepsNode : public DepsNode {
name_tag(-1)
{}
OperationIDKey(eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag)
: opcode(opcode),
name(name),
@ -85,7 +85,7 @@ struct ComponentDepsNode : public DepsNode {
bool operator==(const OperationIDKey &other) const
{
return (opcode == other.opcode) &&
(name == other.name) &&
(STREQ(name, other.name)) &&
(name_tag == other.name_tag);
}
};
@ -94,20 +94,20 @@ struct ComponentDepsNode : public DepsNode {
ComponentDepsNode();
~ComponentDepsNode();
void init(const ID *id, const string &subdata);
void init(const ID *id, const char *subdata);
string identifier() const;
/* Find an existing operation, will throw an assert() if it does not exist. */
OperationDepsNode *find_operation(OperationIDKey key) const;
OperationDepsNode *find_operation(eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag) const;
/* Check operation exists and return it. */
OperationDepsNode *has_operation(OperationIDKey key) const;
OperationDepsNode *has_operation(eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag) const;
/**
@ -126,7 +126,7 @@ struct ComponentDepsNode : public DepsNode {
OperationDepsNode *add_operation(eDepsOperation_Type optype,
DepsEvalOperationCb op,
eDepsOperation_Code opcode,
const string &name,
const char *name,
int name_tag);
void clear_operations();
@ -206,7 +206,7 @@ struct PoseComponentDepsNode : public ComponentDepsNode {
/* Bone Component */
struct BoneComponentDepsNode : public ComponentDepsNode {
void init(const ID *id, const string &subdata);
void init(const ID *id, const char *subdata);
struct bPoseChannel *pchan; /* the bone that this component represents */

View File

@ -68,7 +68,7 @@ string OperationDepsNode::full_identifier() const
{
string owner_str = "";
if (owner->type == DEPSNODE_TYPE_BONE) {
owner_str = owner->owner->name + "." + owner->name;
owner_str = string(owner->owner->name) + "." + owner->name;
}
else {
owner_str = owner->owner->name;