[Bf-blender-cvs] [f6baba695cc] master: Curves: Inline some simple methods

Hans Goudey noreply at git.blender.org
Sun Apr 3 19:51:18 CEST 2022


Commit: f6baba695cc0a7fb0efcd2586457466774e8f843
Author: Hans Goudey
Date:   Sun Apr 3 12:51:05 2022 -0500
Branches: master
https://developer.blender.org/rBf6baba695cc0a7fb0efcd2586457466774e8f843

Curves: Inline some simple methods

These functions are very simple, but some of them were showing up in
in profiles for curves sculpt mode and various curve nodes. Making sure
they are inlined will allow avoiding the compiler to optimize this logic
much better.

Differential Revision: https://developer.blender.org/D14529

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

M	source/blender/blenkernel/BKE_curves.hh
M	source/blender/blenkernel/intern/curves_geometry.cc

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

diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index f097acc497f..b233a89c56d 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -552,4 +552,100 @@ Curves *curves_new_nomain(int points_num, int curves_num);
  */
 Curves *curves_new_nomain_single(int points_num, CurveType type);
 
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name #CurvesGeometry Inline Methods
+ * \{ */
+
+inline int CurvesGeometry::points_num() const
+{
+  return this->point_size;
+}
+inline int CurvesGeometry::curves_num() const
+{
+  return this->curve_size;
+}
+inline IndexRange CurvesGeometry::points_range() const
+{
+  return IndexRange(this->points_num());
+}
+inline IndexRange CurvesGeometry::curves_range() const
+{
+  return IndexRange(this->curves_num());
+}
+
+inline IndexRange CurvesGeometry::points_for_curve(const int index) const
+{
+  /* Offsets are not allocated when there are no curves. */
+  BLI_assert(this->curve_size > 0);
+  BLI_assert(this->curve_offsets != nullptr);
+  const int offset = this->curve_offsets[index];
+  const int offset_next = this->curve_offsets[index + 1];
+  return {offset, offset_next - offset};
+}
+
+inline IndexRange CurvesGeometry::points_for_curves(const IndexRange curves) const
+{
+  /* Offsets are not allocated when there are no curves. */
+  BLI_assert(this->curve_size > 0);
+  BLI_assert(this->curve_offsets != nullptr);
+  const int offset = this->curve_offsets[curves.start()];
+  const int offset_next = this->curve_offsets[curves.one_after_last()];
+  return {offset, offset_next - offset};
+}
+
+inline int CurvesGeometry::evaluated_points_num() const
+{
+  /* This could avoid calculating offsets in the future in simple circumstances. */
+  return this->evaluated_offsets().last();
+}
+
+inline IndexRange CurvesGeometry::evaluated_points_for_curve(int index) const
+{
+  BLI_assert(!this->runtime->offsets_cache_dirty);
+  return offsets_to_range(this->runtime->evaluated_offsets_cache.as_span(), index);
+}
+
+inline IndexRange CurvesGeometry::evaluated_points_for_curves(const IndexRange curves) const
+{
+  BLI_assert(!this->runtime->offsets_cache_dirty);
+  BLI_assert(this->curve_size > 0);
+  const int offset = this->runtime->evaluated_offsets_cache[curves.start()];
+  const int offset_next = this->runtime->evaluated_offsets_cache[curves.one_after_last()];
+  return {offset, offset_next - offset};
+}
+
+inline Span<int> CurvesGeometry::bezier_evaluated_offsets_for_curve(const int curve_index) const
+{
+  const IndexRange points = this->points_for_curve(curve_index);
+  return this->runtime->bezier_evaluated_offsets.as_span().slice(points);
+}
+
+inline IndexRange CurvesGeometry::lengths_range_for_curve(const int curve_index,
+                                                          const bool cyclic) const
+{
+  BLI_assert(cyclic == this->cyclic()[curve_index]);
+  const IndexRange points = this->evaluated_points_for_curve(curve_index);
+  const int start = points.start() + curve_index;
+  const int size = curves::curve_segment_size(points.size(), cyclic);
+  return {start, size};
+}
+
+inline Span<float> CurvesGeometry::evaluated_lengths_for_curve(const int curve_index,
+                                                               const bool cyclic) const
+{
+  BLI_assert(!this->runtime->length_cache_dirty);
+  const IndexRange range = this->lengths_range_for_curve(curve_index, cyclic);
+  return this->runtime->evaluated_length_cache.as_span().slice(range);
+}
+
+inline float CurvesGeometry::evaluated_length_total_for_curve(const int curve_index,
+                                                              const bool cyclic) const
+{
+  return this->evaluated_lengths_for_curve(curve_index, cyclic).last();
+}
+
+/** \} */
+
 }  // namespace blender::bke
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 66088714e63..b0a97bb0df8 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -150,41 +150,6 @@ CurvesGeometry::~CurvesGeometry()
 /** \name Accessors
  * \{ */
 
-int CurvesGeometry::points_num() const
-{
-  return this->point_size;
-}
-int CurvesGeometry::curves_num() const
-{
-  return this->curve_size;
-}
-IndexRange CurvesGeometry::points_range() const
-{
-  return IndexRange(this->points_num());
-}
-IndexRange CurvesGeometry::curves_range() const
-{
-  return IndexRange(this->curves_num());
-}
-
-IndexRange CurvesGeometry::points_for_curve(const int index) const
-{
-  BLI_assert(this->curve_size > 0);
-  BLI_assert(this->curve_offsets != nullptr);
-  const int offset = this->curve_offsets[index];
-  const int offset_next = this->curve_offsets[index + 1];
-  return {offset, offset_next - offset};
-}
-
-IndexRange CurvesGeometry::points_for_curves(const IndexRange curves) const
-{
-  BLI_assert(this->curve_size > 0);
-  BLI_assert(this->curve_offsets != nullptr);
-  const int offset = this->curve_offsets[curves.start()];
-  const int offset_next = this->curve_offsets[curves.one_after_last()];
-  return {offset, offset_next - offset};
-}
-
 static int domain_size(const CurvesGeometry &curves, const AttributeDomain domain)
 {
   return domain == ATTR_DOMAIN_POINT ? curves.points_num() : curves.curves_num();
@@ -492,27 +457,6 @@ static void calculate_evaluated_offsets(const CurvesGeometry &curves,
   });
 }
 
-int CurvesGeometry::evaluated_points_num() const
-{
-  /* This could avoid calculating offsets in the future in simple circumstances. */
-  return this->evaluated_offsets().last();
-}
-
-IndexRange CurvesGeometry::evaluated_points_for_curve(int index) const
-{
-  BLI_assert(!this->runtime->offsets_cache_dirty);
-  return offsets_to_range(this->runtime->evaluated_offsets_cache.as_span(), index);
-}
-
-IndexRange CurvesGeometry::evaluated_points_for_curves(const IndexRange curves) const
-{
-  BLI_assert(!this->runtime->offsets_cache_dirty);
-  BLI_assert(this->curve_size > 0);
-  const int offset = this->runtime->evaluated_offsets_cache[curves.start()];
-  const int offset_next = this->runtime->evaluated_offsets_cache[curves.one_after_last()];
-  return {offset, offset_next - offset};
-}
-
 void CurvesGeometry::ensure_evaluated_offsets() const
 {
   if (!this->runtime->offsets_cache_dirty) {
@@ -548,12 +492,6 @@ Span<int> CurvesGeometry::evaluated_offsets() const
   return this->runtime->evaluated_offsets_cache;
 }
 
-Span<int> CurvesGeometry::bezier_evaluated_offsets_for_curve(const int curve_index) const
-{
-  const IndexRange points = this->points_for_curve(curve_index);
-  return this->runtime->bezier_evaluated_offsets.as_span().slice(points);
-}
-
 IndexMask CurvesGeometry::indices_for_curve_type(const CurveType type,
                                                  Vector<int64_t> &r_indices) const
 {
@@ -728,15 +666,6 @@ void CurvesGeometry::interpolate_to_evaluated(const int curve_index,
   BLI_assert_unreachable();
 }
 
-IndexRange CurvesGeometry::lengths_range_for_curve(const int curve_index, const bool cyclic) const
-{
-  BLI_assert(cyclic == this->cyclic()[curve_index]);
-  const IndexRange points = this->evaluated_points_for_curve(curve_index);
-  const int start = points.start() + curve_index;
-  const int size = curves::curve_segment_size(points.size(), cyclic);
-  return {start, size};
-}
-
 void CurvesGeometry::ensure_evaluated_lengths() const
 {
   if (!this->runtime->length_cache_dirty) {
@@ -777,20 +706,6 @@ void CurvesGeometry::ensure_evaluated_lengths() const
   this->runtime->length_cache_dirty = false;
 }
 
-Span<float> CurvesGeometry::evaluated_lengths_for_curve(const int curve_index,
-                                                        const bool cyclic) const
-{
-  BLI_assert(!this->runtime->length_cache_dirty);
-  const IndexRange range = this->lengths_range_for_curve(curve_index, cyclic);
-  return this->runtime->evaluated_length_cache.as_span().slice(range);
-}
-
-float CurvesGeometry::evaluated_length_total_for_curve(const int curve_index,
-                                                       const bool cyclic) const
-{
-  return this->evaluated_lengths_for_curve(curve_index, cyclic).last();
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list