[Bf-blender-cvs] [d819361cc58] functions: simplify allocating tuple in prepared buffer
Jacques Lucke
noreply at git.blender.org
Sun Mar 24 13:52:57 CET 2019
Commit: d819361cc58b1a0d9b88df0f0fca012aab256003
Author: Jacques Lucke
Date: Sun Mar 24 11:31:33 2019 +0100
Branches: functions
https://developer.blender.org/rBd819361cc58b1a0d9b88df0f0fca012aab256003
simplify allocating tuple in prepared buffer
===================================================================
M source/blender/functions/backends/tuple_call/tuple.hpp
M source/blender/functions/c_wrapper.cpp
===================================================================
diff --git a/source/blender/functions/backends/tuple_call/tuple.hpp b/source/blender/functions/backends/tuple_call/tuple.hpp
index 1f0271f55c4..fd17ebd1fac 100644
--- a/source/blender/functions/backends/tuple_call/tuple.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple.hpp
@@ -45,7 +45,7 @@ namespace FN {
return m_total_size;
}
- inline uint total_stack_size() const;
+ inline uint total_size() const;
uint element_amount() const
{
@@ -88,6 +88,17 @@ namespace FN {
}
}
+ static Tuple &NewInBuffer(
+ SharedTupleMeta &meta,
+ void *buffer)
+ {
+ void *tuple_ptr = buffer;
+ void *data_ptr = (char *)buffer + sizeof(Tuple);
+ void *init_ptr = (char *)data_ptr + meta->total_data_size();
+ Tuple *tuple = new(tuple_ptr) Tuple(meta, data_ptr, (bool *)init_ptr, false);
+ return *tuple;
+ }
+
Tuple(SmallTypeVector types)
: Tuple(SharedTupleMeta::New(types)) {}
@@ -307,7 +318,7 @@ namespace FN {
SharedTupleMeta m_meta;
};
- inline uint TupleMeta::total_stack_size() const
+ inline uint TupleMeta::total_size() const
{
return sizeof(Tuple) + this->total_data_size() + this->element_amount();
}
@@ -316,6 +327,5 @@ namespace FN {
#define FN_TUPLE_STACK_ALLOC(name, meta_expr) \
SharedTupleMeta &name##_meta = (meta_expr); \
- void *name##_data = alloca(name##_meta->total_data_size()); \
- bool *name##_initialized = (bool *)alloca(name##_meta->element_amount()); \
- Tuple name(name##_meta, name##_data, name##_initialized, false);
+ void *name##_buffer = alloca(name##_meta->total_size()); \
+ Tuple &name = Tuple::NewInBuffer(name##_meta, name##_buffer);
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index ba1eef480bc..cdc1702842a 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -176,16 +176,7 @@ void FN_tuple_free(FnTuple tuple)
uint fn_tuple_stack_prepare_size(FnTupleCallBody body_)
{
TupleCallBody *body = unwrap(body_);
- return body->meta_in()->total_stack_size() + body->meta_out()->total_stack_size();
-}
-
-static Tuple *init_tuple(SharedTupleMeta &meta, void *buffer)
-{
- char *buf = (char *)buffer;
- char *tuple_buf = buf + 0;
- char *data_buf = buf + sizeof(Tuple);
- char *init_buf = data_buf + meta->total_data_size();
- return new(tuple_buf) Tuple(meta, data_buf, (bool *)init_buf, false);
+ return body->meta_in()->total_size() + body->meta_out()->total_size();
}
void fn_tuple_prepare_stack(
@@ -197,11 +188,11 @@ void fn_tuple_prepare_stack(
TupleCallBody *body = unwrap(body_);
char *buf = (char *)buffer;
char *buf_in = buf + 0;
- char *buf_out = buf + body->meta_in()->total_stack_size();
- Tuple *fn_in = init_tuple(body->meta_in(), buf_in);
- Tuple *fn_out = init_tuple(body->meta_out(), buf_out);
- *fn_in_ = wrap(fn_in);
- *fn_out_ = wrap(fn_out);
+ char *buf_out = buf + body->meta_in()->total_size();
+ Tuple::NewInBuffer(body->meta_in(), buf_in);
+ Tuple::NewInBuffer(body->meta_out(), buf_out);
+ *fn_in_ = wrap((Tuple *)buf_in);
+ *fn_out_ = wrap((Tuple *)buf_out);
}
void fn_tuple_destruct(FnTuple tuple)
More information about the Bf-blender-cvs
mailing list