Cleanup: Use constexpr for geometry nodes string, avoid .c_str()

This commit is contained in:
Hans Goudey
2024-12-04 12:12:29 -05:00
parent 19ab63e513
commit af79b4e7b5
4 changed files with 21 additions and 32 deletions

View File

@@ -671,9 +671,9 @@ static void add_attribute_search_or_value_buttons(uiLayout *layout,
BLI_str_escape(socket_id_esc, socket.identifier, sizeof(socket_id_esc));
const std::string rna_path = "[\"" + std::string(socket_id_esc) + "\"]";
const std::string rna_path_use_attribute = "[\"" + std::string(socket_id_esc) +
nodes::input_use_attribute_suffix() + "\"]";
nodes::input_use_attribute_suffix + "\"]";
const std::string rna_path_attribute_name = "[\"" + std::string(socket_id_esc) +
nodes::input_attribute_name_suffix() + "\"]";
nodes::input_attribute_name_suffix + "\"]";
/* We're handling this manually in this case. */
uiLayoutSetPropDecorate(layout, false);

View File

@@ -2002,9 +2002,9 @@ static void attribute_search_exec_fn(bContext *C, void *data_v, void *item_v)
}
const std::string attribute_prop_name = data.socket_identifier +
nodes::input_attribute_name_suffix();
nodes::input_attribute_name_suffix;
IDProperty &name_property = *IDP_GetPropertyFromGroup(nmd->settings.properties,
attribute_prop_name.c_str());
attribute_prop_name);
IDP_AssignString(&name_property, item.name.c_str());
ED_undo_push(C, "Assign Attribute Name");
@@ -2085,7 +2085,7 @@ static void add_attribute_search_or_value_buttons(const bContext &C,
BLI_str_escape(socket_id_esc, identifier.c_str(), sizeof(socket_id_esc));
const std::string rna_path = "[\"" + std::string(socket_id_esc) + "\"]";
const std::string rna_path_attribute_name = "[\"" + std::string(socket_id_esc) +
nodes::input_attribute_name_suffix() + "\"]";
nodes::input_attribute_name_suffix + "\"]";
/* We're handling this manually in this case. */
uiLayoutSetPropDecorate(layout, false);
@@ -2144,7 +2144,7 @@ static void draw_property_for_socket(const bContext &C,
{
const StringRefNull identifier = socket.identifier;
/* The property should be created in #MOD_nodes_update_interface with the correct type. */
IDProperty *property = IDP_GetPropertyFromGroup(nmd->settings.properties, identifier.c_str());
IDProperty *property = IDP_GetPropertyFromGroup(nmd->settings.properties, identifier);
/* IDProperties can be removed with python, so there could be a situation where
* there isn't a property for a socket or it doesn't have the correct type. */
@@ -2223,7 +2223,7 @@ static void draw_property_for_output_socket(const bContext &C,
char socket_id_esc[MAX_NAME * 2];
BLI_str_escape(socket_id_esc, identifier.c_str(), sizeof(socket_id_esc));
const std::string rna_path_attribute_name = "[\"" + StringRef(socket_id_esc) +
nodes::input_attribute_name_suffix() + "\"]";
nodes::input_attribute_name_suffix + "\"]";
uiLayout *split = uiLayoutSplit(layout, 0.4f, false);
uiLayout *name_row = uiLayoutRow(split, false);

View File

@@ -32,8 +32,8 @@ void find_node_tree_dependencies(const bNodeTree &tree,
bool &r_needs_own_transform_relation,
bool &r_needs_scene_camera_relation);
StringRef input_use_attribute_suffix();
StringRef input_attribute_name_suffix();
constexpr StringRef input_use_attribute_suffix = "_use_attribute";
constexpr StringRef input_attribute_name_suffix = "_attribute_name";
std::optional<StringRef> input_attribute_name_get(const IDProperty &props,
const bNodeTreeInterfaceSocket &io_input);

View File

@@ -144,16 +144,6 @@ void find_node_tree_dependencies(const bNodeTree &tree,
tree, r_ids, r_needs_own_transform_relation, r_needs_scene_camera_relation, checked_groups);
}
StringRef input_use_attribute_suffix()
{
return "_use_attribute";
}
StringRef input_attribute_name_suffix()
{
return "_attribute_name";
}
bool socket_type_has_attribute_toggle(const eNodeSocketDatatype type)
{
return socket_type_supports_fields(type);
@@ -679,7 +669,7 @@ std::optional<StringRef> input_attribute_name_get(const IDProperty &props,
const bNodeTreeInterfaceSocket &io_input)
{
IDProperty *use_attribute = IDP_GetPropertyFromGroup(
&props, (std::string(io_input.identifier) + input_use_attribute_suffix()).c_str());
&props, io_input.identifier + input_use_attribute_suffix);
if (!use_attribute) {
return std::nullopt;
}
@@ -695,7 +685,7 @@ std::optional<StringRef> input_attribute_name_get(const IDProperty &props,
}
const IDProperty *property_attribute_name = IDP_GetPropertyFromGroup(
&props, (io_input.identifier + input_attribute_name_suffix()).c_str());
&props, io_input.identifier + input_attribute_name_suffix);
return IDP_String(property_attribute_name);
}
@@ -773,8 +763,8 @@ static MultiValueMap<bke::AttrDomain, OutputAttributeInfo> find_output_attribute
continue;
}
const std::string prop_name = socket->identifier + input_attribute_name_suffix();
const IDProperty *prop = IDP_GetPropertyFromGroup(properties, prop_name.c_str());
const std::string prop_name = socket->identifier + input_attribute_name_suffix;
const IDProperty *prop = IDP_GetPropertyFromGroup(properties, prop_name);
if (prop == nullptr) {
continue;
}
@@ -1067,8 +1057,7 @@ void update_input_properties_from_node_tree(const bNodeTree &tree,
IDP_AddToGroup(&properties, new_prop);
if (old_properties != nullptr) {
const IDProperty *old_prop = IDP_GetPropertyFromGroup(old_properties,
socket_identifier.c_str());
const IDProperty *old_prop = IDP_GetPropertyFromGroup(old_properties, socket_identifier);
if (old_prop != nullptr) {
/* Re-use the value (and only the value!) from the old property if possible, handling
* conversion to new property's type as needed. */
@@ -1078,8 +1067,8 @@ void update_input_properties_from_node_tree(const bNodeTree &tree,
}
if (socket_type_has_attribute_toggle(eNodeSocketDatatype(socket_type))) {
const std::string use_attribute_id = socket_identifier + input_use_attribute_suffix();
const std::string attribute_name_id = socket_identifier + input_attribute_name_suffix();
const std::string use_attribute_id = socket_identifier + input_use_attribute_suffix;
const std::string attribute_name_id = socket_identifier + input_attribute_name_suffix;
IDProperty *use_attribute_prop = bke::idprop::create_bool(use_attribute_id, false).release();
IDP_AddToGroup(&properties, use_attribute_prop);
@@ -1095,13 +1084,13 @@ void update_input_properties_from_node_tree(const bNodeTree &tree,
}
else {
IDProperty *old_prop_use_attribute = IDP_GetPropertyFromGroup(old_properties,
use_attribute_id.c_str());
use_attribute_id);
if (old_prop_use_attribute != nullptr) {
IDP_CopyPropertyContent(use_attribute_prop, old_prop_use_attribute);
}
IDProperty *old_attribute_name_prop = IDP_GetPropertyFromGroup(old_properties,
attribute_name_id.c_str());
attribute_name_id);
if (old_attribute_name_prop != nullptr) {
IDP_CopyPropertyContent(attribute_prop, old_attribute_name_prop);
}
@@ -1126,8 +1115,8 @@ void update_output_properties_from_node_tree(const bNodeTree &tree,
continue;
}
const std::string idprop_name = socket_identifier + input_attribute_name_suffix();
IDProperty *new_prop = IDP_NewStringMaxSize("", MAX_NAME, idprop_name.c_str());
const std::string idprop_name = socket_identifier + input_attribute_name_suffix;
IDProperty *new_prop = IDP_NewStringMaxSize("", MAX_NAME, idprop_name);
if (socket.description && socket.description[0] != '\0') {
IDPropertyUIData *ui_data = IDP_ui_data_ensure(new_prop);
ui_data->description = BLI_strdup(socket.description);
@@ -1140,7 +1129,7 @@ void update_output_properties_from_node_tree(const bNodeTree &tree,
}
}
else {
IDProperty *old_prop = IDP_GetPropertyFromGroup(old_properties, idprop_name.c_str());
IDProperty *old_prop = IDP_GetPropertyFromGroup(old_properties, idprop_name);
if (old_prop != nullptr) {
/* #IDP_CopyPropertyContent replaces the UI data as well, which we don't (we only
* want to replace the values). So release it temporarily and replace it after. */