Commit: 499c24ce7530b484b103fa714e94fc72ef6acfc2
Author: Jacques Lucke
Date:   Wed Nov 24 17:49:33 2021 +0100
Branches: master
https://developer.blender.org/rB499c24ce7530b484b103fa714e94fc72ef6acfc2

BLI: add slice method to index mask and generic span

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

M       source/blender/blenlib/BLI_index_mask.hh
M       source/blender/blenlib/intern/index_mask.cc
M       source/blender/functions/FN_generic_span.hh

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

diff --git a/source/blender/blenlib/BLI_index_mask.hh 
b/source/blender/blenlib/BLI_index_mask.hh
index ad030e127fe..16bb8c931cc 100644
--- a/source/blender/blenlib/BLI_index_mask.hh
+++ b/source/blender/blenlib/BLI_index_mask.hh
@@ -223,6 +223,7 @@ class IndexMask {
     return indices_.is_empty();
   }
 
+  IndexMask slice(IndexRange slice) const;
   IndexMask slice_and_offset(IndexRange slice, Vector<int64_t> &r_new_indices) 
const;
 };
 
diff --git a/source/blender/blenlib/intern/index_mask.cc 
b/source/blender/blenlib/intern/index_mask.cc
index cba985b8a44..d726dff6d16 100644
--- a/source/blender/blenlib/intern/index_mask.cc
+++ b/source/blender/blenlib/intern/index_mask.cc
@@ -18,6 +18,11 @@
 
 namespace blender {
 
+IndexMask IndexMask::slice(IndexRange slice) const
+{
+  return IndexMask(indices_.slice(slice));
+}
+
 /**
  * Create a sub-mask that is also shifted to the beginning. The shifting to 
the beginning allows
  * code to work with smaller indices, which is more memory efficient.
diff --git a/source/blender/functions/FN_generic_span.hh 
b/source/blender/functions/FN_generic_span.hh
index e2c49697ba9..6f0147b7fb3 100644
--- a/source/blender/functions/FN_generic_span.hh
+++ b/source/blender/functions/FN_generic_span.hh
@@ -93,6 +93,11 @@ class GSpan {
     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);
   }
+
+  GSpan slice(const IndexRange range) const
+  {
+    return this->slice(range.start(), range.size());
+  }
 };
 
 /**
@@ -169,6 +174,11 @@ class GMutableSpan {
     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);
   }
+
+  GMutableSpan slice(IndexRange range) const
+  {
+    return this->slice(range.start(), range.size());
+  }
 };
 
 }  // namespace blender::fn

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to