Animation: minor speedup when accessing id properties

This is fundamentally quadratic code until #140907 is implemented. However, the
old approach that didn't use `StringRef` was a few percent faster because it
didn't have to call `strlen` as often. So this brings back a little bit of
performance in cases like #140706.

Pull Request: https://projects.blender.org/blender/blender/pulls/144012
This commit is contained in:
Jacques Lucke
2025-08-07 16:38:04 +02:00
parent 7f8d01f809
commit 3f94a4ab1c
2 changed files with 14 additions and 0 deletions

View File

@@ -191,6 +191,13 @@ void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL();
IDProperty *IDP_GetPropertyFromGroup(const IDProperty *prop,
blender::StringRef name) ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL();
/**
* This is a slightly more efficient version of the function above in the when there are lots of
* properties. It can be faster because it avoids computing the length of everything that the
* string is compared to. Also see #140706.
*/
IDProperty *IDP_GetPropertyFromGroup(const IDProperty *prop,
const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
/**
* Same as #IDP_GetPropertyFromGroup but ensure the `type` matches.
*/

View File

@@ -769,6 +769,13 @@ IDProperty *IDP_GetPropertyFromGroup(const IDProperty *prop, const blender::Stri
return BLI_listbase_find<IDProperty>(prop->data.group,
[&](const IDProperty &elem) { return elem.name == name; });
}
IDProperty *IDP_GetPropertyFromGroup(const IDProperty *prop, const char *name)
{
BLI_assert(prop->type == IDP_GROUP);
return (IDProperty *)BLI_findstring(&prop->data.group, name, offsetof(IDProperty, name));
}
IDProperty *IDP_GetPropertyTypeFromGroup(const IDProperty *prop,
const blender::StringRef name,
const char type)