Skip to content
Snippets Groups Projects
Commit bd780aea authored by Alice Ryhl's avatar Alice Ryhl Committed by Miguel Ojeda
Browse files

rust: sync: add `Arc::ptr_eq`


Add a method for comparing whether two `Arc` pointers reference the same
underlying object.

This comparison can already be done by getting a reference to the inner
values and comparing whether the references have the same address.
However, writing `Arc::ptr_eq(a, b)` is generally less error-prone than
doing the same check on the references, since you might otherwise
accidentally compare the two `&Arc<T>` references instead, which wont
work because those are pointers to pointers to the inner value, when you
just want to compare the pointers to the inner value.

Also, this method might optimize better because getting a reference to
the inner value involves offsetting the pointer, which this method does
not need to do.

Co-developed-by: default avatarWedson Almeida Filho <walmeida@microsoft.com>
Signed-off-by: default avatarWedson Almeida Filho <walmeida@microsoft.com>
Signed-off-by: default avatarAlice Ryhl <aliceryhl@google.com>
Reviewed-by: default avatarBenno Lossin <benno.lossin@proton.me>
Reviewed-by: default avatarGary Guo <gary@garyguo.net>
Reviewed-by: Martin Rodriguez Reboredo's avatarMartin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: default avatarAndreas Hindborg <a.hindborg@samsung.com>
Link: https://lore.kernel.org/r/20230517200814.3157916-1-aliceryhl@google.com


Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent e37b654c
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment