From 67700ced54e4a395444b13991fd230bb69558ccc Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 28 Apr 2023 16:14:03 +0200 Subject: [PATCH] BLI: Add "take front" and "take back" methods to bit spans This is consistent with `Span`, and also allows returning a bounded bit span when taking the front of an existing bounded span, which can simplify using optimized bit processing. Pull Request: https://projects.blender.org/blender/blender/pulls/107441 --- .../blender/blenkernel/intern/mesh_mirror.cc | 4 +-- source/blender/blenlib/BLI_bit_span.hh | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/mesh_mirror.cc b/source/blender/blenkernel/intern/mesh_mirror.cc index ca787acbbf5..8f94717b281 100644 --- a/source/blender/blenkernel/intern/mesh_mirror.cc +++ b/source/blender/blenkernel/intern/mesh_mirror.cc @@ -336,8 +336,8 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, const blender::BoundedBitSpan src = mesh->runtime->subsurf_optimal_display_edges; result->runtime->subsurf_optimal_display_edges.resize(result->totedge); blender::MutableBoundedBitSpan dst = result->runtime->subsurf_optimal_display_edges; - dst.slice({0, src.size()}).copy_from(src); - dst.slice({src.size(), src.size()}).copy_from(src); + dst.take_front(src.size()).copy_from(src); + dst.take_back(src.size()).copy_from(src); } /* handle uvs, diff --git a/source/blender/blenlib/BLI_bit_span.hh b/source/blender/blenlib/BLI_bit_span.hh index 36dbb91bc65..2e8088793df 100644 --- a/source/blender/blenlib/BLI_bit_span.hh +++ b/source/blender/blenlib/BLI_bit_span.hh @@ -110,6 +110,16 @@ class BitSpan { return {data_, bit_range_.slice(range)}; } + BitSpan take_front(const int64_t n) const + { + return {data_, bit_range_.take_front(n)}; + } + + BitSpan take_back(const int64_t n) const + { + return {data_, bit_range_.take_back(n)}; + } + const BitInt *data() const { return data_; @@ -195,6 +205,11 @@ class BoundedBitSpan : public BitSpan { { return bit_range_.size() & BitIndexMask; } + + BoundedBitSpan take_front(const int64_t n) const + { + return {data_, bit_range_.take_front(n)}; + } }; /** Same as #BitSpan, but also allows modifying the referenced bits. */ @@ -237,6 +252,16 @@ class MutableBitSpan { return {data_, bit_range_.slice(range)}; } + MutableBitSpan take_front(const int64_t n) const + { + return {data_, bit_range_.take_front(n)}; + } + + MutableBitSpan take_back(const int64_t n) const + { + return {data_, bit_range_.take_back(n)}; + } + BitInt *data() const { return data_; @@ -331,6 +356,11 @@ class MutableBoundedBitSpan : public MutableBitSpan { return bit_range_.size() & BitIndexMask; } + MutableBoundedBitSpan take_front(const int64_t n) const + { + return {data_, bit_range_.take_front(n)}; + } + void copy_from(const BitSpan other); void copy_from(const BoundedBitSpan other); };