[Bf-blender-cvs] [5460fa6efcd] functions: store StringRef directly in function
Jacques Lucke
noreply at git.blender.org
Thu Sep 26 16:51:33 CEST 2019
Commit: 5460fa6efcd25424603e0a7e2c20dd2f5fb8ca20
Author: Jacques Lucke
Date: Thu Sep 26 12:46:51 2019 +0200
Branches: functions
https://developer.blender.org/rB5460fa6efcd25424603e0a7e2c20dd2f5fb8ca20
store StringRef directly in function
That increases the size slightly, but is easier to debug
===================================================================
M source/blender/functions/core/function.cpp
M source/blender/functions/core/function.hpp
M source/blender/functions/core/function_builder.cpp
===================================================================
diff --git a/source/blender/functions/core/function.cpp b/source/blender/functions/core/function.cpp
index d7164220693..30940272c61 100644
--- a/source/blender/functions/core/function.cpp
+++ b/source/blender/functions/core/function.cpp
@@ -5,10 +5,10 @@ namespace FN {
/* Function
**********************************************/
-Function::Function(ChainedStringRef name,
- ArrayRef<ChainedStringRef> input_names,
+Function::Function(StringRefNull name,
+ ArrayRef<StringRefNull> input_names,
ArrayRef<Type *> input_types,
- ArrayRef<ChainedStringRef> output_names,
+ ArrayRef<StringRefNull> output_names,
ArrayRef<Type *> output_types,
const char *strings)
: m_name(name),
diff --git a/source/blender/functions/core/function.hpp b/source/blender/functions/core/function.hpp
index ae72694dbdd..7f11968e1be 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -56,10 +56,10 @@ class Function final : public RefCounter {
* Construct a new function. Instead of calling this directly, the FunctionBuilder should be
* used.
*/
- Function(ChainedStringRef name,
- ArrayRef<ChainedStringRef> input_names,
+ Function(StringRefNull name,
+ ArrayRef<StringRefNull> input_names,
ArrayRef<Type *> input_types,
- ArrayRef<ChainedStringRef> output_names,
+ ArrayRef<StringRefNull> output_names,
ArrayRef<Type *> output_types,
const char *strings);
@@ -150,13 +150,13 @@ class Function final : public RefCounter {
void print();
private:
- ChainedStringRef m_name;
+ StringRefNull m_name;
std::mutex m_add_body_mutex;
FunctionBody *m_bodies[FunctionBody::BODY_TYPE_AMOUNT] = {0};
- Vector<ChainedStringRef> m_input_names;
+ Vector<StringRefNull> m_input_names;
Vector<Type *> m_input_types;
- Vector<ChainedStringRef> m_output_names;
+ Vector<StringRefNull> m_output_names;
Vector<Type *> m_output_types;
const char *m_strings;
@@ -169,7 +169,7 @@ using SharedFunction = AutoRefCount<Function>;
inline const StringRefNull Function::name() const
{
- return m_name.to_string_ref(m_strings);
+ return m_name;
}
#define STATIC_ASSERT_BODY_TYPE(T) \
@@ -234,12 +234,12 @@ inline Type *Function::output_type(uint index) const
inline StringRefNull Function::input_name(uint index) const
{
- return m_input_names[index].to_string_ref(m_strings);
+ return m_input_names[index];
}
inline StringRefNull Function::output_name(uint index) const
{
- return m_output_names[index].to_string_ref(m_strings);
+ return m_output_names[index];
}
template<typename T> inline Vector<T *> Function::input_extensions() const
diff --git a/source/blender/functions/core/function_builder.cpp b/source/blender/functions/core/function_builder.cpp
index 8ac9893bc11..6981612d4fa 100644
--- a/source/blender/functions/core/function_builder.cpp
+++ b/source/blender/functions/core/function_builder.cpp
@@ -44,8 +44,25 @@ SharedFunction FunctionBuilder::build(StringRef function_name)
{
auto name_ref = m_strings_builder.add(function_name);
char *strings = m_strings_builder.build();
- return SharedFunction::New(
- name_ref, m_input_names, m_input_types, m_output_names, m_output_types, strings);
+
+ Vector<StringRefNull> input_names;
+ Vector<StringRefNull> output_names;
+ input_names.reserve(m_input_names.size());
+ output_names.reserve(m_output_names.size());
+
+ for (ChainedStringRef name : m_input_names) {
+ input_names.append(name.to_string_ref(strings));
+ }
+ for (ChainedStringRef name : m_output_names) {
+ output_names.append(name.to_string_ref(strings));
+ }
+
+ return SharedFunction::New(name_ref.to_string_ref(strings),
+ input_names,
+ m_input_types,
+ output_names,
+ m_output_types,
+ strings);
}
} // namespace FN
More information about the Bf-blender-cvs
mailing list