[Bf-blender-cvs] [5ef500c27bd] functions: cleanup arrayref and stringref

Jacques Lucke noreply at git.blender.org
Mon Aug 26 15:50:45 CEST 2019


Commit: 5ef500c27bdb12b9ee71b2c6f74e56641ae37452
Author: Jacques Lucke
Date:   Mon Aug 26 15:48:26 2019 +0200
Branches: functions
https://developer.blender.org/rB5ef500c27bdb12b9ee71b2c6f74e56641ae37452

cleanup arrayref and stringref

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

M	source/blender/blenlib/BLI_array_ref.hpp
M	source/blender/blenlib/BLI_string_ref.hpp
M	source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp

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

diff --git a/source/blender/blenlib/BLI_array_ref.hpp b/source/blender/blenlib/BLI_array_ref.hpp
index 49954ced86a..9c305f0efc3 100644
--- a/source/blender/blenlib/BLI_array_ref.hpp
+++ b/source/blender/blenlib/BLI_array_ref.hpp
@@ -17,18 +17,18 @@
 /** \file
  * \ingroup bli
  *
- * This classes offer a convenient way to work with continuous chunks of memory of a certain type.
+ * These classes offer a convenient way to work with continuous chunks of memory of a certain type.
  * We differentiate ArrayRef and MutableArrayRef. The elements in the former are const while the
  * elements in the other are not.
  *
  * Passing array references as parameters has multiple benefits:
- *   - Less templates are used since the function does not have to work with different
+ *   - Less templates are used because the function does not have to work with different
  *     container types.
  *   - It encourages an Struct-of-Arrays data layout which is often benefitial when
  *     writing high performance code. Also it makes it easier to reuse code.
  *   - Array references offer convenient ways of slicing and other operations.
  *
- * The instrances of ArrayRef and MutableArrayRef are very small and should be passed by value.
+ * The instances of ArrayRef and MutableArrayRef are very small and should be passed by value.
  * Since array references do not own any memory, it is generally not save to store them.
  */
 
@@ -78,7 +78,7 @@ template<typename T> class ArrayRef {
 
   /**
    * Return a continuous part of the array.
-   * This will assert when the slice is out of bounds.
+   * Asserts that the slice stays within the array.
    */
   ArrayRef slice(uint start, uint length) const
   {
@@ -88,6 +88,7 @@ template<typename T> class ArrayRef {
 
   /**
    * Return a new ArrayRef with n elements removed from the beginning.
+   * Asserts that the array contains enough elements.
    */
   ArrayRef drop_front(uint n = 1) const
   {
@@ -97,6 +98,7 @@ template<typename T> class ArrayRef {
 
   /**
    * Return a new ArrayRef with n elements removed from the beginning.
+   * Asserts that the array contains enough elements.
    */
   ArrayRef drop_back(uint n = 1) const
   {
@@ -106,6 +108,7 @@ template<typename T> class ArrayRef {
 
   /**
    * Return a new ArrayRef that only contains the first n elements.
+   * Asserts that the array contains enough elements.
    */
   ArrayRef take_front(uint n) const
   {
@@ -115,6 +118,7 @@ template<typename T> class ArrayRef {
 
   /**
    * Return a new ArrayRef that only contains the last n elements.
+   * Asserts that the array contains enough elements.
    */
   ArrayRef take_back(uint n) const
   {
@@ -140,6 +144,10 @@ template<typename T> class ArrayRef {
     return m_start + m_size;
   }
 
+  /**
+   * Access an element in the array.
+   * Asserts that the index is in the bounds of the array.
+   */
   const T &operator[](uint index) const
   {
     BLI_assert(index < m_size);
@@ -202,7 +210,7 @@ template<typename T> class ArrayRef {
 
   /**
    * Return a reference to the first element in the array.
-   * Asserts when the array is empty.
+   * Asserts that the array is not empty.
    */
   const T &first() const
   {
@@ -212,7 +220,7 @@ template<typename T> class ArrayRef {
 
   /**
    * Return a reference to the last elemeent in the array.
-   * Asserts when the array is empty.
+   * Asserts that the array is not empty.
    */
   const T &last() const
   {
@@ -348,7 +356,7 @@ template<typename T> class MutableArrayRef {
 
   /**
    * Return a continuous part of the array.
-   * This will assert when the slice is out of bounds.
+   * Aserts that the slice stays in the array bounds.
    */
   MutableArrayRef slice(uint start, uint length) const
   {
diff --git a/source/blender/blenlib/BLI_string_ref.hpp b/source/blender/blenlib/BLI_string_ref.hpp
index 00648cc0957..01edb004b55 100644
--- a/source/blender/blenlib/BLI_string_ref.hpp
+++ b/source/blender/blenlib/BLI_string_ref.hpp
@@ -126,11 +126,6 @@ class StringRefNull : public StringRefBase {
   StringRefNull(const std::string &str) : StringRefNull(str.data())
   {
   }
-
-  operator const char *() const
-  {
-    return m_data;
-  }
 };
 
 class StringRef : public StringRefBase {
@@ -166,7 +161,7 @@ class StringRef : public StringRefBase {
 
   /**
    * Return a new StringRef that with the given prefix being skipped.
-   * Asserts when the string does not begin with the prefix.
+   * Asserts that the string begins with the given prefix.
    */
   StringRef drop_prefix(StringRef prefix) const
   {
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
index 51b762f8dd8..e96fc1b4169 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
@@ -318,7 +318,7 @@ Type *VTreeDataGraphBuilder::query_type_property(VirtualNode *vnode, StringRefNu
 Type *VTreeDataGraphBuilder::type_from_rna(PointerRNA &rna, StringRefNull prop_name) const
 {
   char type_name[64];
-  RNA_string_get(&rna, prop_name, type_name);
+  RNA_string_get(&rna, prop_name.data(), type_name);
   return this->type_by_name(type_name);
 }



More information about the Bf-blender-cvs mailing list