ConstName#

Fully qualified name: omni::graph::exec::unstable::ConstName

Structs#

BogusArg

Implementation detail. Ignore.

class ConstName#

An immutable name with fast hash based comparisons.

ConstName is a hash of a given string. This hash is used for all comparisons. The original string is also stored in this object.

Prefer using the overloaded comparison operators (e.g. ==, <, !=) rather than performing comparison operators with the result of toString() or getString(). Using the comparison operators is considerably faster.

Comparison of ConstName with const char*, omni::string, or std::string is potentially slow and as such no comparison operators exist to do so. To compare a ConstName with either a const char*, omni::string, or std::string, you must first explicitly create a ConstName from the string.

Classes like carb::RString and pxr::TfToken also utilize a hash of an original string for fast string comparison. In these classes, the hash is simply passed around but the string is stored in a global lookup table. When the original string is needed, the hash is used as a lookup in the global table.

Unlike carb::RString and pxr::TfToken, ConstName avoids the global table. Rather, the original string is stored alongside the hash. The benefit of avoiding the global table is speed. Performance testing revealed that when constructing names of objects during graph traversal, the cost of multiple threads reading and writing to the global tables storing carb::RString and pxr::TfToken’s strings was a bottleneck.

If you need speed in threaded code, use ConstName. If you want to save space, use carb::RString or pxr::TfToken.

This class can safely be passed by pointer across the ABI. However, since it is not a trivial type, it cannot be passed by value across the ABI. See OMNI_STATIC_ASSERT_CAN_BE_PASSED_BY_VALUE_IN_ABI() for details.

Thread Safety

Methods in this class are thread safe unless otherwise noted.

Public Functions

template<std::size_t N>
inline explicit ConstName(const char (&s)[N])#

Construct from a static compile time string.

inline explicit ConstName(const carb::cpp::string_view &sv)#

Construct from a carb::cpp::string_view. This constructor also accepts const char *.

inline explicit ConstName(
const carb::cpp::string_view &sv,
NameHash hash,
)#

Construct from a carb::cpp::string_view with an already computed hash.

inline ConstName() noexcept#

Construct from empty string.

template<typename T>
inline explicit ConstName(
const T &s,
std::enable_if_t<std::is_same<std::string, T>::value, BogusArg> = {},
)#

Construct from a std::string.

template<typename T>
inline explicit ConstName(
const T &s,
NameHash hash,
std::enable_if_t<std::is_same<std::string, T>::value, BogusArg> = {},
)#

Construct from a std::string and a pre-computed hash.

inline const omni::string &getString() const noexcept#

Returns the string used to generate the hash. For debugging purposes only.

Thread Safety

This method is thread safe.

inline constexpr uint64_t getHash() const noexcept#

Returns the hash used for comparison.

Prefer using the overloaded comparison operators (e.g. <, ==) rather than directly calling this method.

Thread Safety

This method is thread safe.

inline std::string toString() const noexcept#

Converts to a std::string. For debugging purposes only.

Prefer using getString() over this method, as getString() does not copy any data.

Thread Safety

This method is thread safe.

inline const char *c_str() const noexcept#

Returns the name as a null-terminated const char*.

Thread Safety

This method is thread safe.

inline operator carb::cpp::string_view() const noexcept#

Implicit conversion to carb::cpp::string_view.

Thread Safety

This method is thread safe.

struct BogusArg#

Implementation detail. Ignore.