Fixes dumb perf overhead for Vec getting extensions
This commit is contained in:
parent
e666bb5a0e
commit
a92b9c096a
|
@ -13,12 +13,12 @@ impl<T> VecExt<T> for [T] {
|
||||||
fn get_mut_res(&mut self, index: usize) -> Result<&mut T> {
|
fn get_mut_res(&mut self, index: usize) -> Result<&mut T> {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
self.get_mut(index)
|
self.get_mut(index)
|
||||||
.ok_or(PkmnError::IndexOutOfBounds { index, len }.into())
|
.ok_or_else(|| PkmnError::IndexOutOfBounds { index, len }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_res(&self, index: usize) -> Result<&T> {
|
fn get_res(&self, index: usize) -> Result<&T> {
|
||||||
self.get(index)
|
self.get(index)
|
||||||
.ok_or(PkmnError::IndexOutOfBounds { index, len: self.len() }.into())
|
.ok_or_else(|| PkmnError::IndexOutOfBounds { index, len: self.len() }.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ impl<T> VecExt<T> for Vec<T> {
|
||||||
fn get_mut_res(&mut self, index: usize) -> Result<&mut T> {
|
fn get_mut_res(&mut self, index: usize) -> Result<&mut T> {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
self.get_mut(index)
|
self.get_mut(index)
|
||||||
.ok_or(PkmnError::IndexOutOfBounds { index, len }.into())
|
.ok_or_else(|| PkmnError::IndexOutOfBounds { index, len }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_res(&self, index: usize) -> Result<&T> {
|
fn get_res(&self, index: usize) -> Result<&T> {
|
||||||
self.get(index)
|
self.get(index)
|
||||||
.ok_or(PkmnError::IndexOutOfBounds { index, len: self.len() }.into())
|
.ok_or_else(|| PkmnError::IndexOutOfBounds { index, len: self.len() }.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue