Skip to content

Commit

Permalink
Avoid cloning Arcs unnecessarily when iterating trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
nical committed Dec 13, 2024
1 parent 3918a09 commit 4a3617a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions wgpu-core/src/track/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl BufferTracker {
}

/// Returns a list of all buffers tracked.
pub fn used_resources(&self) -> impl Iterator<Item = Arc<Buffer>> + '_ {
pub fn used_resources(&self) -> impl Iterator<Item = &Arc<Buffer>> + '_ {
self.metadata.owned_resources()
}

Expand Down Expand Up @@ -559,7 +559,7 @@ impl DeviceBufferTracker {
}

/// Returns a list of all buffers tracked.
pub fn used_resources(&self) -> impl Iterator<Item = Weak<Buffer>> + '_ {
pub fn used_resources(&self) -> impl Iterator<Item = &Weak<Buffer>> + '_ {
self.metadata.owned_resources()
}

Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/track/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ impl<T: Clone> ResourceMetadata<T> {
}

/// Returns an iterator over the resources owned by `self`.
pub(super) fn owned_resources(&self) -> impl Iterator<Item = T> + '_ {
pub(super) fn owned_resources(&self) -> impl Iterator<Item = &T> + '_ {
if !self.owned.is_empty() {
self.tracker_assert_in_bounds(self.owned.len() - 1)
};
iterate_bitvec_indices(&self.owned).map(move |index| {
let resource = unsafe { self.resources.get_unchecked(index) };
resource.as_ref().unwrap().clone()
resource.as_ref().unwrap()
})
}

Expand Down
5 changes: 2 additions & 3 deletions wgpu-core/src/track/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,9 @@ impl TextureTracker {
}

/// Returns a list of all textures tracked.
pub fn used_resources(&self) -> impl Iterator<Item = Arc<Texture>> + '_ {
pub fn used_resources(&self) -> impl Iterator<Item = &Arc<Texture>> + '_ {
self.metadata.owned_resources()
}

/// Drain all currently pending transitions.
pub fn drain_transitions<'a>(
&'a mut self,
Expand Down Expand Up @@ -672,7 +671,7 @@ impl DeviceTextureTracker {
}

/// Returns a list of all textures tracked.
pub fn used_resources(&self) -> impl Iterator<Item = Weak<Texture>> + '_ {
pub fn used_resources(&self) -> impl Iterator<Item = &Weak<Texture>> + '_ {
self.metadata.owned_resources()
}

Expand Down

0 comments on commit 4a3617a

Please sign in to comment.