Skip to content

Commit a60e71c

Browse files
andyleisersonteoxoy
authored andcommitted
Clarify comment about Arc::as_ptr
1 parent 50a2613 commit a60e71c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

wgpu-core/src/id.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@ impl<T: Marker> Hash for PointerId<T> {
161161

162162
impl<T: StorageItem> From<&Arc<T>> for PointerId<T::Marker> {
163163
fn from(arc: &Arc<T>) -> Self {
164-
// Since the memory representation of `Arc<T>` is just a pointer, it
165-
// would be nice to use that pointer as the trace ID, since many
166-
// `into_trace` implementations would then be no-ops at runtime.
167-
// Unfortunately, because `Arc::as_ptr` returns a pointer to the
168-
// contained data, and `Arc` stores reference counts before the data,
169-
// we are adding an offset to the pointer here.
164+
// Since the memory representation of `Arc<T>` is just a pointer to
165+
// `ArcInner<T>`, it would be nice to use that pointer as the trace ID,
166+
// since many `into_trace` implementations would then be no-ops at
167+
// runtime. However, `Arc::as_ptr` returns a pointer to the contained
168+
// data, not to the `ArcInner`. The `ArcInner` stores the reference
169+
// counts before the data, so the machine code for this conversion has
170+
// to add an offset to the pointer.
170171
PointerId::PointerId(Arc::as_ptr(arc) as usize, PhantomData)
171172
}
172173
}

0 commit comments

Comments
 (0)