[Bf-blender-cvs] [5ae3fa50e22] master: Cleanup: Remove misleading std::string reference binding

Hans Goudey noreply at git.blender.org
Tue Aug 30 01:12:14 CEST 2022


Commit: 5ae3fa50e224700e5722ecbe641692776bba0567
Author: Hans Goudey
Date:   Mon Aug 29 18:11:37 2022 -0500
Branches: master
https://developer.blender.org/rB5ae3fa50e224700e5722ecbe641692776bba0567

Cleanup: Remove misleading std::string reference binding

These functions that retrieve strings from assets return stringrefs.
Storing them as std::strings is unnecessary and relies on binding to
the const references.

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

M	source/blender/editors/asset/intern/asset_indexer.cc

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

diff --git a/source/blender/editors/asset/intern/asset_indexer.cc b/source/blender/editors/asset/intern/asset_indexer.cc
index 3cc3638c299..cc06fa80429 100644
--- a/source/blender/editors/asset/intern/asset_indexer.cc
+++ b/source/blender/editors/asset/intern/asset_indexer.cc
@@ -351,7 +351,7 @@ static void init_indexer_entry_from_value(FileIndexerEntry &indexer_entry,
 {
   indexer_entry.idcode = entry.get_idcode();
 
-  const std::string &name = entry.get_name();
+  const std::string name = entry.get_name();
   BLI_strncpy(
       indexer_entry.datablock_info.name, name.c_str(), sizeof(indexer_entry.datablock_info.name));
 
@@ -359,19 +359,19 @@ static void init_indexer_entry_from_value(FileIndexerEntry &indexer_entry,
   indexer_entry.datablock_info.asset_data = asset_data;
 
   if (entry.has_description()) {
-    const std::string &description = entry.get_description();
-    char *description_c_str = static_cast<char *>(MEM_mallocN(description.length() + 1, __func__));
-    BLI_strncpy(description_c_str, description.c_str(), description.length() + 1);
+    const StringRefNull description = entry.get_description();
+    char *description_c_str = static_cast<char *>(MEM_mallocN(description.size() + 1, __func__));
+    BLI_strncpy(description_c_str, description.c_str(), description.size() + 1);
     asset_data->description = description_c_str;
   }
   if (entry.has_author()) {
-    const std::string &author = entry.get_author();
-    char *author_c_str = static_cast<char *>(MEM_mallocN(author.length() + 1, __func__));
-    BLI_strncpy(author_c_str, author.c_str(), author.length() + 1);
+    const StringRefNull author = entry.get_author();
+    char *author_c_str = static_cast<char *>(MEM_mallocN(author.size() + 1, __func__));
+    BLI_strncpy(author_c_str, author.c_str(), author.size() + 1);
     asset_data->author = author_c_str;
   }
 
-  const std::string &catalog_name = entry.get_catalog_name();
+  const StringRefNull catalog_name = entry.get_catalog_name();
   BLI_strncpy(asset_data->catalog_simple_name,
               catalog_name.c_str(),
               sizeof(asset_data->catalog_simple_name));



More information about the Bf-blender-cvs mailing list