Closed Bug 1546853 Opened 5 years ago Closed 5 years ago

mozilla::Variant should permit hashing on the variant tag

Categories

(Core :: MFBT, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: jimb, Assigned: jimb)

References

Details

Attachments

(1 file)

The discriminant of a mozilla::Variant value is not available via Variant's public interface, but since it is considered in the operator== implementation, it would be nice if it hashing a Variant could conveniently take the tag into account.

Hashing a Variant will probably involve a match to hash the individual alternatives' contents, and those match branches could of course each perturb the hash in a different way, but this essentially requires the match branches to create their own tag, when Variant has a usable value right there. This approach also doesn't work well with when match branches are templated member functions.

Define the Variant::addToHash method, which perturbs a hash value according to
the variant's current alternative's tag. This makes it easier to avoid
collisions in variants in which different alternatives might hash similarly.

Tests included.

Attachment #9060601 - Attachment description: Bug 1546853: Implement mozilla::Variant::addToHash. r?froydnj → Bug 1546853: Implement mozilla::Variant::addTagToHash. r?froydnj
Pushed by jblandy@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6dea6fe4571e
Implement mozilla::Variant::addTagToHash. r=froydnj
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
Assignee: nobody → jimb
See Also: → 1548133
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: