Skip to content

Rework hashing in C++ #2123

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 10 commits into from
May 8, 2024
Merged

Conversation

bernardnormier
Copy link
Member

This PR reworks the hashing in C++.

The only public hashing in C++ is for proxies. It is now exposed as a std::hash specialization of Ice::ObjectPrx.
It's used primarily by the C++-based language mappings: Python and Ruby. Strangely, it does not appear to be used by PHP.

@bernardnormier bernardnormier requested review from pepone and externl May 6, 2024 21:21
{
int value = Reference::hashInit();
hashAdd(value, _adapterId);
Copy link
Member Author

Choose a reason for hiding this comment

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

In a remarkable twist, we were not including endpoints at all in the hash. As a result, all the endpoint hashing was completely unused!

I double checked - this code is identical on 3.7.

}

inline void hashAdd(std::int32_t& hashCode, const std::string& value)
inline void hashAdd(std::size_t& hashCode, const std::vector<EndpointIPtr>& seq)
{
Copy link
Member

Choose a reason for hiding this comment

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

We could add the container's size to the hash, when hashing a collection.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather keep the same logic as in C#.

In C#, since we treat null collection = empty collection, and we skip nulls, we can't add the size of the collection to the hash.

@bernardnormier bernardnormier merged commit 74a086b into zeroc-ice:main May 8, 2024
16 checks passed
@bernardnormier bernardnormier deleted the cpp-hash branch May 10, 2024 23:44
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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.

3 participants