Skip to content

api(ustringhash): make a public explicit ustringhash ctr from hash value #3778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/include/OpenImageIO/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,13 @@ class OIIO_UTIL_API ustringhash {
#endif
}

/// Construct from a raw hash value. Beware: results are undefined if it's
/// not the valid hash of a ustring.
OIIO_HOSTDEVICE explicit constexpr ustringhash(hash_t hash) noexcept
: m_hash(hash)
{
}

/// Conversion to an OIIO::string_view.
operator string_view() const noexcept { return ustring::from_hash(m_hash); }

Expand Down Expand Up @@ -965,7 +972,7 @@ class OIIO_UTIL_API ustringhash {
#endif

/// Return the ustringhash corresponding to the given hash. Caveat emptor:
/// results are undefined if it's not the valud hash of a ustring.
/// results are undefined if it's not the valid hash of a ustring.
OIIO_NODISCARD static constexpr ustringhash from_hash(hash_t hash)
{
ustringhash u;
Expand All @@ -977,13 +984,6 @@ class OIIO_UTIL_API ustringhash {
// Individual ustringhash internal representation -- the hash value.
rep_t m_hash;

// Construct from a raw hash value. It's protected so that it's only
// callable by its friend, ustring.
OIIO_HOSTDEVICE ustringhash(hash_t hashval)
: m_hash(hashval)
{
}

friend class ustring;
};

Expand Down