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.
This commit is contained in:
myreprise1 2023-02-11 08:28:14 +00:00
parent c791b21d91
commit de98850a3e
2 changed files with 3 additions and 18 deletions

View File

@ -102,12 +102,7 @@ impl Edges {
/// Removes an edge from the `input_edges` if it exists.
pub(crate) fn remove_input_edge(&mut self, edge: Edge) -> Result<(), RenderGraphError> {
if let Some((index, _)) = self
.input_edges
.iter()
.enumerate()
.find(|(_i, e)| **e == edge)
{
if let Some(index) = self.input_edges.iter().position(|e| *e == edge) {
self.input_edges.swap_remove(index);
Ok(())
} else {
@ -126,12 +121,7 @@ impl Edges {
/// Removes an edge from the `output_edges` if it exists.
pub(crate) fn remove_output_edge(&mut self, edge: Edge) -> Result<(), RenderGraphError> {
if let Some((index, _)) = self
.output_edges
.iter()
.enumerate()
.find(|(_i, e)| **e == edge)
{
if let Some(index) = self.output_edges.iter().position(|e| *e == edge) {
self.output_edges.swap_remove(index);
Ok(())
} else {

View File

@ -188,12 +188,7 @@ impl SlotInfos {
let label = label.into();
match label {
SlotLabel::Index(index) => Some(index),
SlotLabel::Name(ref name) => self
.slots
.iter()
.enumerate()
.find(|(_i, s)| s.name == *name)
.map(|(i, _s)| i),
SlotLabel::Name(ref name) => self.slots.iter().position(|s| s.name == *name),
}
}