Cleanup: unify naming between different spans

This commit is contained in:
Jacques Lucke 2020-07-23 18:07:31 +02:00
parent 87c0a38a39
commit 149bb0c26d
9 changed files with 65 additions and 65 deletions

@ -87,7 +87,7 @@ namespace blender {
*/
template<typename T> class Span {
private:
const T *start_ = nullptr;
const T *data_ = nullptr;
int64_t size_ = 0;
public:
@ -96,13 +96,13 @@ template<typename T> class Span {
*/
Span() = default;
Span(const T *start, int64_t size) : start_(start), size_(size)
Span(const T *start, int64_t size) : data_(start), size_(size)
{
BLI_assert(size >= 0);
}
template<typename U, typename std::enable_if_t<is_convertible_pointer_v<U, T>> * = nullptr>
Span(const U *start, int64_t size) : start_((const T *)start), size_(size)
Span(const U *start, int64_t size) : data_((const T *)start), size_(size)
{
BLI_assert(size >= 0);
}
@ -136,7 +136,7 @@ template<typename T> class Span {
* Span<Derived *> -> Span<Base *>
*/
template<typename U, typename std::enable_if_t<is_convertible_pointer_v<U, T>> * = nullptr>
Span(Span<U> array) : start_((T *)array.data()), size_(array.size())
Span(Span<U> array) : data_((T *)array.data()), size_(array.size())
{
}
@ -149,7 +149,7 @@ template<typename T> class Span {
BLI_assert(start >= 0);
BLI_assert(size >= 0);
BLI_assert(start + size <= this->size() || size == 0);
return Span(start_ + start, size);
return Span(data_ + start, size);
}
Span slice(IndexRange range) const
@ -207,17 +207,17 @@ template<typename T> class Span {
*/
const T *data() const
{
return start_;
return data_;
}
const T *begin() const
{
return start_;
return data_;
}
const T *end() const
{
return start_ + size_;
return data_ + size_;
}
/**
@ -228,7 +228,7 @@ template<typename T> class Span {
{
BLI_assert(index >= 0);
BLI_assert(index < size_);
return start_[index];
return data_[index];
}
/**
@ -300,7 +300,7 @@ template<typename T> class Span {
const T &first() const
{
BLI_assert(size_ > 0);
return start_[0];
return data_[0];
}
/**
@ -310,7 +310,7 @@ template<typename T> class Span {
const T &last() const
{
BLI_assert(size_ > 0);
return start_[size_ - 1];
return data_[size_ - 1];
}
/**
@ -320,7 +320,7 @@ template<typename T> class Span {
T get(int64_t index, const T &fallback) const
{
if (index < size_ && index >= 0) {
return start_[index];
return data_[index];
}
return fallback;
}
@ -336,9 +336,9 @@ template<typename T> class Span {
BLI_assert(size_ < 1000);
for (int64_t i = 0; i < size_; i++) {
const T &value = start_[i];
const T &value = data_[i];
for (int64_t j = i + 1; j < size_; j++) {
if (value == start_[j]) {
if (value == data_[j]) {
return true;
}
}
@ -358,7 +358,7 @@ template<typename T> class Span {
BLI_assert(size_ < 1000);
for (int64_t i = 0; i < size_; i++) {
const T &value = start_[i];
const T &value = data_[i];
if (other.contains(value)) {
return true;
}
@ -383,7 +383,7 @@ template<typename T> class Span {
int64_t first_index_try(const T &search_value) const
{
for (int64_t i = 0; i < size_; i++) {
if (start_[i] == search_value) {
if (data_[i] == search_value) {
return i;
}
}
@ -406,7 +406,7 @@ template<typename T> class Span {
{
BLI_assert((size_ * sizeof(T)) % sizeof(NewT) == 0);
int64_t new_size = size_ * sizeof(T) / sizeof(NewT);
return Span<NewT>(reinterpret_cast<const NewT *>(start_), new_size);
return Span<NewT>(reinterpret_cast<const NewT *>(data_), new_size);
}
/**
@ -439,13 +439,13 @@ template<typename T> class Span {
*/
template<typename T> class MutableSpan {
private:
T *start_;
T *data_;
int64_t size_;
public:
MutableSpan() = default;
MutableSpan(T *start, const int64_t size) : start_(start), size_(size)
MutableSpan(T *start, const int64_t size) : data_(start), size_(size)
{
}
@ -459,7 +459,7 @@ template<typename T> class MutableSpan {
operator Span<T>() const
{
return Span<T>(start_, size_);
return Span<T>(data_, size_);
}
/**
@ -475,7 +475,7 @@ template<typename T> class MutableSpan {
*/
void fill(const T &value)
{
initialized_fill_n(start_, size_, value);
initialized_fill_n(data_, size_, value);
}
/**
@ -486,7 +486,7 @@ template<typename T> class MutableSpan {
{
for (int64_t i : indices) {
BLI_assert(i < size_);
start_[i] = value;
data_[i] = value;
}
}
@ -496,23 +496,23 @@ template<typename T> class MutableSpan {
*/
T *data() const
{
return start_;
return data_;
}
T *begin() const
{
return start_;
return data_;
}
T *end() const
{
return start_ + size_;
return data_ + size_;
}
T &operator[](const int64_t index) const
{
BLI_assert(index < this->size());
return start_[index];
return data_[index];
}
/**
@ -522,7 +522,7 @@ template<typename T> class MutableSpan {
MutableSpan slice(const int64_t start, const int64_t length) const
{
BLI_assert(start + length <= this->size());
return MutableSpan(start_ + start, length);
return MutableSpan(data_ + start, length);
}
/**
@ -571,7 +571,7 @@ template<typename T> class MutableSpan {
*/
Span<T> as_span() const
{
return Span<T>(start_, size_);
return Span<T>(data_, size_);
}
/**
@ -590,7 +590,7 @@ template<typename T> class MutableSpan {
T &last() const
{
BLI_assert(size_ > 0);
return start_[size_ - 1];
return data_[size_ - 1];
}
/**
@ -616,7 +616,7 @@ template<typename T> class MutableSpan {
void copy_from(Span<T> values)
{
BLI_assert(size_ == values.size());
initialized_copy_n(values.data(), size_, start_);
initialized_copy_n(values.data(), size_, data_);
}
/**
@ -626,7 +626,7 @@ template<typename T> class MutableSpan {
{
BLI_assert((size_ * sizeof(T)) % sizeof(NewT) == 0);
int64_t new_size = size_ * sizeof(T) / sizeof(NewT);
return MutableSpan<NewT>(reinterpret_cast<NewT *>(start_), new_size);
return MutableSpan<NewT>(reinterpret_cast<NewT *>(data_), new_size);
}
};

@ -158,7 +158,7 @@ class GVArraySpan : public VArraySpanBase<void> {
this->type_ = &array.type();
this->virtual_size_ = virtual_size;
this->category_ = VArraySpanCategory::SingleArray;
this->data_.single_array.start = array.buffer();
this->data_.single_array.start = array.data();
this->data_.single_array.size = array.size();
}

@ -51,12 +51,12 @@ namespace blender::fn {
class GSpan {
private:
const CPPType *type_;
const void *buffer_;
const void *data_;
int64_t size_;
public:
GSpan(const CPPType &type, const void *buffer, int64_t size)
: type_(&type), buffer_(buffer), size_(size)
: type_(&type), data_(buffer), size_(size)
{
BLI_assert(size >= 0);
BLI_assert(buffer != nullptr || size == 0);
@ -87,21 +87,21 @@ class GSpan {
return size_;
}
const void *buffer() const
const void *data() const
{
return buffer_;
return data_;
}
const void *operator[](int64_t index) const
{
BLI_assert(index < size_);
return POINTER_OFFSET(buffer_, type_->size() * index);
return POINTER_OFFSET(data_, type_->size() * index);
}
template<typename T> Span<T> typed() const
{
BLI_assert(type_->is<T>());
return Span<T>((const T *)buffer_, size_);
return Span<T>((const T *)data_, size_);
}
};
@ -112,12 +112,12 @@ class GSpan {
class GMutableSpan {
private:
const CPPType *type_;
void *buffer_;
void *data_;
int64_t size_;
public:
GMutableSpan(const CPPType &type, void *buffer, int64_t size)
: type_(&type), buffer_(buffer), size_(size)
: type_(&type), data_(buffer), size_(size)
{
BLI_assert(size >= 0);
BLI_assert(buffer != nullptr || size == 0);
@ -136,7 +136,7 @@ class GMutableSpan {
operator GSpan() const
{
return GSpan(*type_, buffer_, size_);
return GSpan(*type_, data_, size_);
}
const CPPType &type() const
@ -154,21 +154,21 @@ class GMutableSpan {
return size_;
}
void *buffer()
void *data()
{
return buffer_;
return data_;
}
void *operator[](int64_t index)
{
BLI_assert(index < size_);
return POINTER_OFFSET(buffer_, type_->size() * index);
return POINTER_OFFSET(data_, type_->size() * index);
}
template<typename T> MutableSpan<T> typed()
{
BLI_assert(type_->is<T>());
return MutableSpan<T>((T *)buffer_, size_);
return MutableSpan<T>((T *)data_, size_);
}
};
@ -311,7 +311,7 @@ class GVSpan : public VSpanBase<void> {
this->type_ = &values.type();
this->virtual_size_ = values.size();
this->category_ = VSpanCategory::FullArray;
this->data_.full_array.data = values.buffer();
this->data_.full_array.data = values.data();
}
GVSpan(GMutableSpan values) : GVSpan(GSpan(values))

@ -34,7 +34,7 @@ void CustomMF_GenericConstant::call(IndexMask mask,
MFContext UNUSED(context)) const
{
GMutableSpan output = params.uninitialized_single_output(0);
type_.fill_uninitialized_indices(value_, output.buffer(), mask);
type_.fill_uninitialized_indices(value_, output.data(), mask);
}
uint64_t CustomMF_GenericConstant::hash() const
@ -111,7 +111,7 @@ void CustomMF_DefaultOutput::call(IndexMask mask, MFParams params, MFContext UNU
if (param_type.data_type().is_single()) {
GMutableSpan span = params.uninitialized_single_output(param_index);
const CPPType &type = span.type();
type.fill_uninitialized_indices(type.default_value(), span.buffer(), mask);
type.fill_uninitialized_indices(type.default_value(), span.data(), mask);
}
}
}

@ -390,7 +390,7 @@ BLI_NOINLINE void MFNetworkEvaluator::initialize_remaining_outputs(
case MFDataType::Single: {
GVSpan values = storage.get_single_input__full(*socket);
GMutableSpan output_values = params.uninitialized_single_output(param_index);
values.materialize_to_uninitialized(storage.mask(), output_values.buffer());
values.materialize_to_uninitialized(storage.mask(), output_values.data());
break;
}
case MFDataType::Vector: {
@ -524,11 +524,11 @@ MFNetworkEvaluationStorage::~MFNetworkEvaluationStorage()
GMutableSpan span = value->span;
const CPPType &type = span.type();
if (value->is_single_allocated) {
type.destruct(span.buffer());
type.destruct(span.data());
}
else {
type.destruct_indices(span.buffer(), mask_);
MEM_freeN(span.buffer());
type.destruct_indices(span.data(), mask_);
MEM_freeN(span.data());
}
}
else if (any_value->type == ValueType::OwnVector) {
@ -634,11 +634,11 @@ void MFNetworkEvaluationStorage::finish_input_socket(const MFInputSocket &socket
GMutableSpan span = value->span;
const CPPType &type = span.type();
if (value->is_single_allocated) {
type.destruct(span.buffer());
type.destruct(span.data());
}
else {
type.destruct_indices(span.buffer(), mask_);
MEM_freeN(span.buffer());
type.destruct_indices(span.data(), mask_);
MEM_freeN(span.data());
}
value_per_output_id_[origin.id()] = nullptr;
}
@ -791,7 +791,7 @@ GMutableSpan MFNetworkEvaluationStorage::get_mutable_single__full(const MFInputS
BLI_assert(to_any_value->type == ValueType::OutputSingle);
GMutableSpan span = ((OutputSingleValue *)to_any_value)->span;
GVSpan virtual_span = this->get_single_input__full(input);
virtual_span.materialize_to_uninitialized(mask_, span.buffer());
virtual_span.materialize_to_uninitialized(mask_, span.data());
return span;
}
@ -808,7 +808,7 @@ GMutableSpan MFNetworkEvaluationStorage::get_mutable_single__full(const MFInputS
GVSpan virtual_span = this->get_single_input__full(input);
void *new_buffer = MEM_mallocN_aligned(min_array_size_ * type.size(), type.alignment(), AT);
GMutableSpan new_array_ref(type, new_buffer, min_array_size_);
virtual_span.materialize_to_uninitialized(mask_, new_array_ref.buffer());
virtual_span.materialize_to_uninitialized(mask_, new_array_ref.data());
OwnSingleValue *new_value = allocator_.construct<OwnSingleValue>(
new_array_ref, to.targets().size(), false);
@ -953,7 +953,7 @@ GVSpan MFNetworkEvaluationStorage::get_single_input__full(const MFInputSocket &s
if (any_value->type == ValueType::OwnSingle) {
OwnSingleValue *value = (OwnSingleValue *)any_value;
if (value->is_single_allocated) {
return GVSpan::FromSingle(value->span.type(), value->span.buffer(), min_array_size_);
return GVSpan::FromSingle(value->span.type(), value->span.data(), min_array_size_);
}
else {
return value->span;

@ -265,7 +265,7 @@ static Array<MFOutputSocket *> add_constant_folded_sockets(const MultiFunction &
case MFDataType::Single: {
const CPPType &cpp_type = data_type.single_type();
GMutableSpan array = params.computed_array(param_index);
void *buffer = array.buffer();
void *buffer = array.data();
resources.add(buffer, array.type().destruct_cb(), AT);
constant_fn = &resources.construct<CustomMF_GenericConstant>(AT, cpp_type, buffer);

@ -68,7 +68,7 @@ fn::MutableAttributesRef ParticleAllocator::allocate(int size)
}
}
else {
type.fill_uninitialized(info.default_of(i), attributes.get(i).buffer(), size);
type.fill_uninitialized(info.default_of(i), attributes.get(i).data(), size);
}
}
return attributes;

@ -234,7 +234,7 @@ BLI_NOINLINE static void remove_dead_and_add_new_particles(ParticleSimulationSta
if (layer.data != nullptr) {
MEM_freeN(layer.data);
}
layer.data = new_buffer.buffer();
layer.data = new_buffer.data();
}
BLI_assert(dead_layer != nullptr);

@ -68,10 +68,10 @@ TEST(mutable_attributes_ref, ComplexTest)
MutableAttributesRef attributes{info, buffers, IndexRange(1, 3)};
EXPECT_EQ(attributes.size(), 3);
EXPECT_EQ(attributes.info().size(), 4);
EXPECT_EQ(attributes.get("Position").buffer(), positions.data() + 1);
EXPECT_EQ(attributes.get("ID").buffer(), ids.data() + 1);
EXPECT_EQ(attributes.get("Size").buffer(), sizes.data() + 1);
EXPECT_EQ(attributes.get("Name").buffer(), names.data() + 1);
EXPECT_EQ(attributes.get("Position").data(), positions.data() + 1);
EXPECT_EQ(attributes.get("ID").data(), ids.data() + 1);
EXPECT_EQ(attributes.get("Size").data(), sizes.data() + 1);
EXPECT_EQ(attributes.get("Name").data(), names.data() + 1);
EXPECT_EQ(attributes.get("ID").size(), 3);
EXPECT_EQ(attributes.get<uint>("ID").size(), 3);