There are a couple of functions that create rna pointers. For example `RNA_main_pointer_create` and `RNA_pointer_create`. Currently, those take an output parameter `r_ptr` as last argument. This patch changes it so that the functions actually return a` PointerRNA` instead of using the output parameters. This has a few benefits: * Output parameters should only be used when there is an actual benefit. Otherwise, one should default to returning the value. * It's simpler to use the API in the large majority of cases (note that this patch reduces the number of lines of code). * It allows the `PointerRNA` to be const on the call-site, if that is desired. No performance regression has been measured in production files. If one of these functions happened to be called in a hot loop where there is a regression, the solution should be to use an inline function there which allows the compiler to optimize it even better. Pull Request: https://projects.blender.org/blender/blender/pulls/111976
110 lines
2.7 KiB
C++
110 lines
2.7 KiB
C++
/* SPDX-FileCopyrightText: 2013 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup depsgraph
|
|
*
|
|
* Methods for constructing depsgraph
|
|
*/
|
|
|
|
#include "intern/builder/deg_builder_key.h"
|
|
|
|
#include "RNA_path.hh"
|
|
|
|
namespace blender::deg {
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
/** \name Time source
|
|
* \{ */
|
|
|
|
string TimeSourceKey::identifier() const
|
|
{
|
|
return string("TimeSourceKey");
|
|
}
|
|
|
|
/** \} */
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
/** \name Component
|
|
* \{ */
|
|
|
|
string ComponentKey::identifier() const
|
|
{
|
|
const char *idname = (id) ? id->name : "<None>";
|
|
string result = string("ComponentKey(");
|
|
result += idname;
|
|
result += ", " + string(nodeTypeAsString(type));
|
|
if (name[0] != '\0') {
|
|
result += ", '" + string(name) + "'";
|
|
}
|
|
result += ')';
|
|
return result;
|
|
}
|
|
|
|
/** \} */
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
/** \name Operation
|
|
* \{ */
|
|
|
|
string OperationKey::identifier() const
|
|
{
|
|
string result = string("OperationKey(");
|
|
result += "type: " + string(nodeTypeAsString(component_type));
|
|
result += ", component name: '" + string(component_name) + "'";
|
|
result += ", operation code: " + string(operationCodeAsString(opcode));
|
|
if (name[0] != '\0') {
|
|
result += ", '" + string(name) + "'";
|
|
}
|
|
result += ")";
|
|
return result;
|
|
}
|
|
|
|
/** \} */
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
/** \name RNA path
|
|
* \{ */
|
|
|
|
RNAPathKey::RNAPathKey(ID *id, const char *path, RNAPointerSource source) : id(id), source(source)
|
|
{
|
|
/* Create ID pointer for root of path lookup. */
|
|
PointerRNA id_ptr = RNA_id_pointer_create(id);
|
|
/* Try to resolve path. */
|
|
int index;
|
|
if (!RNA_path_resolve_full(&id_ptr, path, &ptr, &prop, &index)) {
|
|
ptr = PointerRNA_NULL;
|
|
prop = nullptr;
|
|
}
|
|
}
|
|
|
|
RNAPathKey::RNAPathKey(ID *id, const PointerRNA &ptr, PropertyRNA *prop, RNAPointerSource source)
|
|
: id(id), ptr(ptr), prop(prop), source(source)
|
|
{
|
|
}
|
|
|
|
RNAPathKey::RNAPathKey(const PointerRNA &target_prop,
|
|
const char *rna_path_from_target_prop,
|
|
const RNAPointerSource source)
|
|
: id(target_prop.owner_id), source(source)
|
|
{
|
|
/* Try to resolve path. */
|
|
int index;
|
|
if (!RNA_path_resolve_full(&target_prop, rna_path_from_target_prop, &ptr, &prop, &index)) {
|
|
ptr = PointerRNA_NULL;
|
|
prop = nullptr;
|
|
}
|
|
}
|
|
|
|
string RNAPathKey::identifier() const
|
|
{
|
|
const char *id_name = (id) ? id->name : "<No ID>";
|
|
const char *prop_name = (prop) ? RNA_property_identifier(prop) : "<No Prop>";
|
|
return string("RnaPathKey(") + "id: " + id_name + ", prop: '" + prop_name + "')";
|
|
}
|
|
|
|
/** \} */
|
|
|
|
} // namespace blender::deg
|