[Bf-blender-cvs] [e93a37c] depsgraph_refactor: Depsgraph: Get rid of depsgraph_string_util

Sergey Sharybin noreply at git.blender.org
Mon Dec 8 11:25:34 CET 2014


Commit: e93a37c33e1f54eb8c730b1bb31fb05a2c38dd41
Author: Sergey Sharybin
Date:   Mon Dec 8 13:56:32 2014 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rBe93a37c33e1f54eb8c730b1bb31fb05a2c38dd41

Depsgraph: Get rid of depsgraph_string_util

All the usages of the string_format could be replaces with
simple string concatinaiton. And further more, i'd prefer
using char* instead of strings to either names coming from
IDs or to statically allocated strings. Would be much better
from the performance point of view.

===================================================================

M	source/blender/depsgraph/CMakeLists.txt
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_build.cpp
M	source/blender/depsgraph/intern/depsgraph_build.h
M	source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
M	source/blender/depsgraph/intern/depsgraph_build_relations.cpp
M	source/blender/depsgraph/intern/depsgraph_debug.cpp
M	source/blender/depsgraph/intern/depsgraph_debug.h
M	source/blender/depsgraph/intern/depsgraph_type_defines.cpp
M	source/blender/depsgraph/intern/depsgraph_types.h
M	source/blender/depsgraph/intern/depsnode.h
D	source/blender/depsgraph/util/depsgraph_util_string.h

===================================================================

diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index c395b62..3d0c9aa 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -78,7 +78,6 @@ set(SRC
 	util/depsgraph_util_map.h
 	util/depsgraph_util_rna.h
 	util/depsgraph_util_set.h
-	util/depsgraph_util_string.h
 	util/depsgraph_util_task.h
 	util/depsgraph_util_task.cpp
 )
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 727ec0b..2c71034 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -41,7 +41,6 @@
 
 #include "depsgraph_util_map.h"
 #include "depsgraph_util_set.h"
-#include "depsgraph_util_string.h"
 
 using std::vector;
 
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cpp b/source/blender/depsgraph/intern/depsgraph_build.cpp
index 4a06739..5cc2bb3 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build.cpp
@@ -98,7 +98,6 @@ extern "C" {
 #include "depsgraph_intern.h"
 
 #include "depsgraph_util_rna.h"
-#include "depsgraph_util_string.h"
 
 #include "stubs.h" // XXX: REMOVE THIS INCLUDE ONCE DEPSGRAPH REFACTOR PROJECT IS DONE!!!
 
@@ -165,7 +164,7 @@ RootDepsNode *DepsgraphNodeBuilder::add_root_node()
 IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id)
 {
 	const char *idtype_name = BKE_idcode_to_name(GS(id->name));
-	return m_graph->add_id_node(id, string_format("%s [%s]", id->name+2, idtype_name));
+	return m_graph->add_id_node(id, string(id->name+2) + "[" + idtype_name + "]");
 }
 
 TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source(ID *id)
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index 2f4892d..fcf9297 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -35,7 +35,6 @@
 
 #include "depsgraph_util_id.h"
 #include "depsgraph_util_rna.h"
-#include "depsgraph_util_string.h"
 
 struct bConstraint;
 struct ListBase;
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
index 7e490f5..d3137f8 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
@@ -97,7 +97,6 @@ extern "C" {
 #include "depsgraph_intern.h"
 
 #include "depsgraph_util_rna.h"
-#include "depsgraph_util_string.h"
 
 #include "stubs.h" // XXX: REMOVE THIS INCLUDE ONCE DEPSGRAPH REFACTOR PROJECT IS DONE!!!
 
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index 9371645..b46994c 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -97,7 +97,6 @@ extern "C" {
 #include "depsgraph_intern.h"
 
 #include "depsgraph_util_rna.h"
-#include "depsgraph_util_string.h"
 
 #include "stubs.h" // XXX: REMOVE THIS INCLUDE ONCE DEPSGRAPH REFACTOR PROJECT IS DONE!!!
 
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cpp b/source/blender/depsgraph/intern/depsgraph_debug.cpp
index 0a2c208..1a7e59b 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cpp
@@ -706,7 +706,7 @@ static string get_component_name(eDepsNode_Type type, const string &name = "")
 	if (name.empty())
 		return string(factory->tname());
 	else
-		return string_format("%s | %s", factory->tname().c_str(), name.c_str());
+		return factory->tname() + " | " + name;
 }
 
 static void times_clear(DepsgraphStatsTimes &times)
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.h b/source/blender/depsgraph/intern/depsgraph_debug.h
index 4d1ff89..83a729a 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.h
+++ b/source/blender/depsgraph/intern/depsgraph_debug.h
@@ -41,7 +41,7 @@ extern "C" {
 #include "DEG_depsgraph_debug.h"
 #include "DEG_depsgraph.h"
 
-#include "depsgraph_util_string.h"
+#include "depsgraph_types.h"
 
 struct DepsgraphStats;
 struct DepsgraphStatsID;
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
index 35cb174..3c121fd 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
@@ -277,15 +277,17 @@ const string deg_op_name_psys_eval = "PSys Eval";
 string deg_op_name_animdata(const ID *id)
 {
 	AnimData *adt = BKE_animdata_from_id((ID *)id);
-	return string_format("AnimData %s : %s", id->name, (adt->action) ? adt->action->id.name : "<None>");
+	return string("AnimData") + id->name + string((adt->action) ? adt->action->id.name : "<None>");
 }
+
 string deg_op_name_driver(const ChannelDriver *driver)
 {
-	return string_format("Driver @ %p", driver);
+	return string("Driver") + driver->expression;
 }
+
 string deg_op_name_modifier(const ModifierData *md)
 {
-	return string_format("Modifier %s", md->name);
+	return string("Modifier") +  md->name;
 }
 
 /* ******************************************************** */
diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h
index 0f22e55..268af69 100644
--- a/source/blender/depsgraph/intern/depsgraph_types.h
+++ b/source/blender/depsgraph/intern/depsgraph_types.h
@@ -34,7 +34,12 @@
 #define __DEPSGRAPH_TYPES_H__
 
 #include "depsgraph_util_function.h"
-#include "depsgraph_util_string.h"
+
+/* TODO(sergey): Ideally we'll just use char* and staticly allocated strings
+ * to avoid any possible overhead caused by string (re)allocation/formatting.
+ */
+#include <string>
+using std::string;
 
 struct bAction;
 struct ChannelDriver;
diff --git a/source/blender/depsgraph/intern/depsnode.h b/source/blender/depsgraph/intern/depsnode.h
index 10f567e..5dd8126 100644
--- a/source/blender/depsgraph/intern/depsnode.h
+++ b/source/blender/depsgraph/intern/depsnode.h
@@ -36,7 +36,6 @@
 #include "depsgraph_util_hash.h"
 #include "depsgraph_util_map.h"
 #include "depsgraph_util_set.h"
-#include "depsgraph_util_string.h"
 
 struct ID;
 struct Scene;
diff --git a/source/blender/depsgraph/util/depsgraph_util_string.h b/source/blender/depsgraph/util/depsgraph_util_string.h
deleted file mode 100644
index a8ab1d8..0000000
--- a/source/blender/depsgraph/util/depsgraph_util_string.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2014 Blender Foundation.
- * All rights reserved.
- *
- * Original Author: Brecht van Lommel
- * Contributor(s): Lukas Toenne
- */
-
-#ifndef __DEPSGRAPH_UTIL_STRING_H__
-#define __DEPSGRAPH_UTIL_STRING_H__
-
-#include <string>
-#include <cstdarg>
-#include <cstdio>
-
-using std::string;
-
-/* format string function working like snprintf
- * http://stackoverflow.com/a/3742999
- */
-inline string string_format(const std::string fmt, ...)
-{
-	string s;
-	int n, size=100;
-	bool b=false;
-	va_list marker;
-
-	while (!b)
-	{
-		s.resize(size);
-		va_start(marker, fmt);
-		n = vsnprintf((char*)s.c_str(), size, fmt.c_str(), marker);
-		va_end(marker);
-		if ((n>0) && ((b=(n<size))==true)) s.resize(n); else size*=2;
-	}
-	return s;
-}
-
-#endif /* __DEPSGRAPH_UTIL_STRING_H__ */




More information about the Bf-blender-cvs mailing list