mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-29 11:01:23 +00:00
obs/gs/effect-parameter: Use string_view over std::string
Using std::string_view over std::string (and const std::string&) has the advantage that we skip potential temporary std::string objects that are immediately thrown away, thus slowing down the code. It can also be implicitly cast to std::string, which makes it compatible with existing code that uses std::string.
This commit is contained in:
parent
9db3dfd874
commit
3a40a63832
3 changed files with 11 additions and 12 deletions
|
@ -36,6 +36,7 @@
|
|||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
|
|
|
@ -112,11 +112,9 @@ try {
|
|||
return *this;
|
||||
}
|
||||
|
||||
std::string gs::effect_parameter::get_name()
|
||||
std::string_view gs::effect_parameter::get_name()
|
||||
{
|
||||
const char* name_c = get()->name;
|
||||
std::size_t name_len = strnlen(name_c, 256);
|
||||
return name_c ? std::string(name_c, name_c + name_len) : std::string();
|
||||
return std::string_view{get()->name};
|
||||
}
|
||||
|
||||
gs::effect_parameter::type gs::effect_parameter::get_type()
|
||||
|
@ -166,11 +164,11 @@ gs::effect_parameter gs::effect_parameter::get_annotation(std::size_t idx)
|
|||
return effect_parameter(get()->annotations.array + idx, this);
|
||||
}
|
||||
|
||||
gs::effect_parameter gs::effect_parameter::get_annotation(std::string name)
|
||||
gs::effect_parameter gs::effect_parameter::get_annotation(const std::string_view name)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < get()->annotations.num; idx++) {
|
||||
auto ptr = get()->annotations.array + idx;
|
||||
if (strcmp(ptr->name, name.c_str()) == 0) {
|
||||
if (name == std::string_view{ptr->name}) {
|
||||
return gs::effect_parameter(ptr, this);
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +176,7 @@ gs::effect_parameter gs::effect_parameter::get_annotation(std::string name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool gs::effect_parameter::has_annotation(std::string name)
|
||||
bool gs::effect_parameter::has_annotation(const std::string_view name)
|
||||
{
|
||||
auto eprm = get_annotation(name);
|
||||
if (eprm)
|
||||
|
@ -186,7 +184,7 @@ bool gs::effect_parameter::has_annotation(std::string name)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool gs::effect_parameter::has_annotation(std::string name, effect_parameter::type type)
|
||||
bool gs::effect_parameter::has_annotation(const std::string_view name, effect_parameter::type type)
|
||||
{
|
||||
auto eprm = get_annotation(name);
|
||||
if (eprm)
|
||||
|
|
|
@ -61,15 +61,15 @@ namespace gs {
|
|||
effect_parameter(effect_parameter&& rhs) noexcept;
|
||||
effect_parameter& operator=(effect_parameter&& rhs) noexcept;
|
||||
|
||||
std::string get_name();
|
||||
std::string_view get_name();
|
||||
|
||||
type get_type();
|
||||
|
||||
std::size_t count_annotations();
|
||||
effect_parameter get_annotation(std::size_t idx);
|
||||
effect_parameter get_annotation(std::string name);
|
||||
bool has_annotation(std::string name);
|
||||
bool has_annotation(std::string name, effect_parameter::type type);
|
||||
effect_parameter get_annotation(const std::string_view name);
|
||||
bool has_annotation(const std::string_view name);
|
||||
bool has_annotation(const std::string_view name, effect_parameter::type type);
|
||||
|
||||
public /* Memory API */:
|
||||
std::size_t get_default_value_size_in_bytes()
|
||||
|
|
Loading…
Reference in a new issue