From ec18e11c37af0f76367671d3d50ff1a3ded9fa0e Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 21 Jun 2023 09:26:18 +0200 Subject: [PATCH] Cleanup: remove unnecessary "for_write" in method name This suffix is only preferred when the non-const version does more work than the const version of a method (e.g. because it may duplicate data because of implicit sharing). --- source/blender/blenlib/BLI_span.hh | 9 +++++++++ source/blender/makesdna/DNA_node_types.h | 2 +- .../nodes/geometry/nodes/node_geo_simulation_output.cc | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh index 93dbd975681..07351203e2d 100644 --- a/source/blender/blenlib/BLI_span.hh +++ b/source/blender/blenlib/BLI_span.hh @@ -746,6 +746,15 @@ template class MutableSpan { return counter; } + /** + * Does a constant time check to see if the pointer points to a value in the referenced array. + * Return true if it is, otherwise false. + */ + constexpr bool contains_ptr(const T *ptr) const + { + return (this->begin() <= ptr) && (ptr < this->end()); + } + /** * Copy all values from another span into this span. This invokes undefined behavior when the * destination contains uninitialized data and T is not trivially copy constructible. diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 076fe448e78..bda27518ab8 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1661,7 +1661,7 @@ typedef struct NodeGeometrySimulationOutput { #ifdef __cplusplus blender::Span items_span() const; - blender::MutableSpan items_span_for_write(); + blender::MutableSpan items_span(); blender::IndexRange items_range() const; #endif } NodeGeometrySimulationOutput; diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc index 2d3e8bfb3f5..fa26c4dc8da 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc @@ -995,7 +995,7 @@ blender::Span NodeGeometrySimulationOutput::items_span() con return blender::Span(items, items_num); } -blender::MutableSpan NodeGeometrySimulationOutput::items_span_for_write() +blender::MutableSpan NodeGeometrySimulationOutput::items_span() { return blender::MutableSpan(items, items_num); } @@ -1077,7 +1077,7 @@ void NOD_geometry_simulation_output_set_active_item(NodeGeometrySimulationOutput NodeSimulationItem *NOD_geometry_simulation_output_find_item(NodeGeometrySimulationOutput *sim, const char *name) { - for (NodeSimulationItem &item : sim->items_span_for_write()) { + for (NodeSimulationItem &item : sim->items_span()) { if (STREQ(item.name, name)) { return &item; } @@ -1164,7 +1164,7 @@ void NOD_geometry_simulation_output_remove_item(NodeGeometrySimulationOutput *si void NOD_geometry_simulation_output_clear_items(NodeGeometrySimulationOutput *sim) { - for (NodeSimulationItem &item : sim->items_span_for_write()) { + for (NodeSimulationItem &item : sim->items_span()) { MEM_SAFE_FREE(item.name); } MEM_SAFE_FREE(sim->items);