Return settings by value with temporaries

* This is slightly less efficient but this isn't high-performance code, and it
  makes settings like shader debug SearchDirPaths safe to access on multiple
  threads.
This commit is contained in:
baldurk
2024-08-29 16:04:56 +01:00
parent f3c10de41c
commit f8a067b709
2 changed files with 13 additions and 18 deletions
+8 -12
View File
@@ -367,29 +367,24 @@ static bool MergeConfigValues(const rdcstr &prefix, SDObject *dstConfig, const S
return ret;
}
const bool &ConfigVarRegistration<bool>::value()
bool ConfigVarRegistration<bool>::value() const
{
// avoid warnings on stupid compilers
(void)tmp;
return obj->data.basic.b;
}
const uint64_t &ConfigVarRegistration<uint64_t>::value()
uint64_t ConfigVarRegistration<uint64_t>::value() const
{
(void)tmp;
return obj->data.basic.u;
}
const uint32_t &ConfigVarRegistration<uint32_t>::value()
uint32_t ConfigVarRegistration<uint32_t>::value() const
{
tmp = obj->data.basic.u & 0xFFFFFFFFU;
return tmp;
return obj->data.basic.u & 0xFFFFFFFFU;
}
const rdcstr &ConfigVarRegistration<rdcstr>::value()
rdcstr ConfigVarRegistration<rdcstr>::value() const
{
tmp = obj->data.str;
return tmp;
return obj->data.str;
}
template <typename T>
@@ -399,8 +394,9 @@ rdcstr DefValString(const T &el)
}
// this one needs a special implementation unfortunately to convert
const rdcarray<rdcstr> &ConfigVarRegistration<rdcarray<rdcstr>>::value()
rdcarray<rdcstr> ConfigVarRegistration<rdcarray<rdcstr>>::value() const
{
rdcarray<rdcstr> tmp;
tmp.resize(obj->NumChildren());
for(size_t i = 0; i < tmp.size(); i++)
tmp[i] = obj->GetChild(i)->data.str;
+5 -6
View File
@@ -40,11 +40,10 @@ struct ConfigVarRegistration;
{ \
ConfigVarRegistration(rdcliteral name, const T &defaultValue, bool debugOnly, \
rdcliteral description); \
const T &value(); \
T value() const; \
\
private: \
SDObject *obj; \
T tmp; \
};
CONFIG_SUPPORT_TYPE(rdcstr);
@@ -58,11 +57,11 @@ CONFIG_SUPPORT_TYPE(rdcarray<rdcstr>);
#define RDOC_CONFIG(type, name, defaultValue, description) \
static ConfigVarRegistration<type> CONCAT(config, __LINE__)( \
STRING_LITERAL(STRINGIZE(name)), defaultValue, false, STRING_LITERAL(description)); \
const type &name() \
type name() \
{ \
return CONCAT(config, __LINE__).value(); \
}
#define RDOC_EXTERN_CONFIG(type, name) extern const type &name();
#define RDOC_EXTERN_CONFIG(type, name) extern type name();
// debug configs get set to constants in official stable builds, they will remain configurable
// in nightly builds and of course in development builds
@@ -71,7 +70,7 @@ CONFIG_SUPPORT_TYPE(rdcarray<rdcstr>);
#define RDOC_DEBUG_CONFIG(type, name, defaultValue, description) \
static ConfigVarRegistration<type> CONCAT(config, __LINE__)( \
STRING_LITERAL(STRINGIZE(name)), defaultValue, true, STRING_LITERAL(description)); \
const type &name() \
type name() \
{ \
static const type ret = defaultValue; \
return ret; \
@@ -81,7 +80,7 @@ CONFIG_SUPPORT_TYPE(rdcarray<rdcstr>);
#define RDOC_DEBUG_CONFIG(type, name, defaultValue, description) \
static ConfigVarRegistration<type> CONCAT(config, __LINE__)( \
STRING_LITERAL(STRINGIZE(name)), defaultValue, true, STRING_LITERAL(description)); \
const type &name() \
type name() \
{ \
return CONCAT(config, __LINE__).value(); \
}