Skip to content

Commit de98850

Browse files
committed
Use position in code when possible (#7621)
# Objective - This makes code a little more readable now. ## Solution - Use `position` provided by `Iter` instead of `enumerating` indices and `map`ping to the index.
1 parent c791b21 commit de98850

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

crates/bevy_render/src/render_graph/node.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ impl Edges {
102102

103103
/// Removes an edge from the `input_edges` if it exists.
104104
pub(crate) fn remove_input_edge(&mut self, edge: Edge) -> Result<(), RenderGraphError> {
105-
if let Some((index, _)) = self
106-
.input_edges
107-
.iter()
108-
.enumerate()
109-
.find(|(_i, e)| **e == edge)
110-
{
105+
if let Some(index) = self.input_edges.iter().position(|e| *e == edge) {
111106
self.input_edges.swap_remove(index);
112107
Ok(())
113108
} else {
@@ -126,12 +121,7 @@ impl Edges {
126121

127122
/// Removes an edge from the `output_edges` if it exists.
128123
pub(crate) fn remove_output_edge(&mut self, edge: Edge) -> Result<(), RenderGraphError> {
129-
if let Some((index, _)) = self
130-
.output_edges
131-
.iter()
132-
.enumerate()
133-
.find(|(_i, e)| **e == edge)
134-
{
124+
if let Some(index) = self.output_edges.iter().position(|e| *e == edge) {
135125
self.output_edges.swap_remove(index);
136126
Ok(())
137127
} else {

crates/bevy_render/src/render_graph/node_slot.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,7 @@ impl SlotInfos {
188188
let label = label.into();
189189
match label {
190190
SlotLabel::Index(index) => Some(index),
191-
SlotLabel::Name(ref name) => self
192-
.slots
193-
.iter()
194-
.enumerate()
195-
.find(|(_i, s)| s.name == *name)
196-
.map(|(i, _s)| i),
191+
SlotLabel::Name(ref name) => self.slots.iter().position(|s| s.name == *name),
197192
}
198193
}
199194

0 commit comments

Comments
 (0)