Skip to content

Short-circuit value equality with an identity check#6372

Merged
maffoo merged 3 commits intomainfrom
u/maffoo/value-eq
Dec 5, 2023
Merged

Short-circuit value equality with an identity check#6372
maffoo merged 3 commits intomainfrom
u/maffoo/value-eq

Conversation

@maffoo
Copy link
Copy Markdown
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 a team, cduck and vtomole 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
@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