Skip to content
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

fix(strutil.h): ensure proper constexpr of string hashing #3901

Merged
merged 1 commit into from
Jul 1, 2023

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Jun 30, 2023

The underlying farmhash algorithm (which is the basis for Strutil::strhash, and thus ustring's hash representation) turned out to not be properly constexpr under certain circumstances and needed to be expressed a different way to be fully constexpr on all platforms and for all strings.

New implementation suggested by Alex Wells.

Also, make sure string_view ctr from char* can be constexpr, even for
C++14. This is related for the sake of the strhash calls that, when
taking string literals, actually choose the variety that accepts a
string_view.

@lgritz lgritz requested a review from AlexMWells June 30, 2023 03:51
@lgritz
Copy link
Collaborator Author

lgritz commented Jun 30, 2023

@AlexMWells, can you confirm if this totally fixes your problem?

@AlexMWells
Copy link
Collaborator

Yes it does fix the issue and allow global constexpr variables and consteval expressions. Thanks for adding a test by the way.

Copy link
Collaborator

@AlexMWells AlexMWells left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The underlying farmhash algorithm (which is the basis for
Strutil::strhash, and thus ustring's hash representation) turned out
to not be properly constexpr under certain circumstances and needed to
be expressed a different way to be fully constexpr on all platforms
and for all strings.

New implementation suggested by Alex Wells.

Also, make sure string_view ctr from char* can be constexpr, even for
C++14. This is related for the sake of the strhash calls that, when
taking string literals, actually choose the variety that accepts a
string_view.

Signed-off-by: Larry Gritz <[email protected]>
@lgritz
Copy link
Collaborator Author

lgritz commented Jun 30, 2023

Updated: Also, make sure string_view ctr from char* can be constexpr, even for
C++14. This is related for the sake of the strhash calls that, when
taking string literals, actually choose the variety that accepts a
string_view.

@lgritz lgritz merged commit 3fd70cf into AcademySoftwareFoundation:master Jul 1, 2023
@lgritz lgritz deleted the lg-hash branch July 1, 2023 07:05
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Jul 1, 2023
…twareFoundation#3901)

The underlying farmhash algorithm (which is the basis for
Strutil::strhash, and thus ustring's hash representation) turned out to
not be properly constexpr under certain circumstances and needed to be
expressed a different way to be fully constexpr on all platforms and for
all strings.

New implementation suggested by Alex Wells.

Also, make sure string_view ctr from char* can be constexpr, even for
C++14. This is related for the sake of the strhash calls that, when
taking string literals, actually choose the variety that accepts a
string_view.

Signed-off-by: Larry Gritz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants