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

Short-circuit value equality with an identity check #6372

Merged
merged 3 commits into from
Dec 5, 2023
Merged

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Dec 5, 2023

We often reuse instances of objects with value semantics, and in such cases equality checking can be short-circuited by first checking for object identity before falling back to actually comparing the values of two objects. This is particular beneficial if we actually take care to reuse instances, which is something we should consider doing more generally to avoid object allocation and repeated computation of various properties such as hashes (see #6371).

We often reuse instances of objects with value semantics, and in such
cases equality checking can be short-circuited by first checking for
object identity before falling back to actually comparing the values of
two objects.
@maffoo maffoo requested review from vtomole, cduck and a team as code owners December 5, 2023 08:11
@maffoo maffoo force-pushed the u/maffoo/value-eq branch from 56521ec to c271084 Compare December 5, 2023 17:21
@maffoo maffoo enabled auto-merge (squash) December 5, 2023 19:42
@maffoo maffoo merged commit be7b059 into main Dec 5, 2023
36 checks passed
@maffoo maffoo deleted the u/maffoo/value-eq branch December 5, 2023 19:53
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
We often reuse instances of objects with value semantics, and in such
cases equality checking can be short-circuited by first checking for
object identity before falling back to actually comparing the values of
two objects.

Review: @95-martin-orion
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