[Bf-blender-cvs] [d5309bf4cf9] master: Functions: add slice method for generic spans
Jacques Lucke
noreply at git.blender.org
Wed Apr 21 17:11:19 CEST 2021
Commit: d5309bf4cf9e36e161027cf7ad1775eb355433f1
Author: Jacques Lucke
Date: Wed Apr 21 16:59:22 2021 +0200
Branches: master
https://developer.blender.org/rBd5309bf4cf9e36e161027cf7ad1775eb355433f1
Functions: add slice method for generic spans
===================================================================
M source/blender/functions/FN_generic_span.hh
===================================================================
diff --git a/source/blender/functions/FN_generic_span.hh b/source/blender/functions/FN_generic_span.hh
index ea2bd49fa09..e2c49697ba9 100644
--- a/source/blender/functions/FN_generic_span.hh
+++ b/source/blender/functions/FN_generic_span.hh
@@ -85,6 +85,14 @@ class GSpan {
BLI_assert(type_->is<T>());
return Span<T>(static_cast<const T *>(data_), size_);
}
+
+ GSpan slice(const int64_t start, int64_t size) const
+ {
+ BLI_assert(start >= 0);
+ BLI_assert(size >= 0);
+ const int64_t new_size = std::max<int64_t>(0, std::min(size, size_ - start));
+ return GSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size);
+ }
};
/**
@@ -153,6 +161,14 @@ class GMutableSpan {
BLI_assert(type_->is<T>());
return MutableSpan<T>(static_cast<T *>(data_), size_);
}
+
+ GMutableSpan slice(const int64_t start, int64_t size) const
+ {
+ BLI_assert(start >= 0);
+ BLI_assert(size >= 0);
+ const int64_t new_size = std::max<int64_t>(0, std::min(size, size_ - start));
+ return GMutableSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size);
+ }
};
} // namespace blender::fn
More information about the Bf-blender-cvs
mailing list