From 6460cf69edc3adc67ffe14b44d79150c219c0eab Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Thu, 14 Sep 2023 20:55:28 -0400 Subject: [PATCH] Small vec cleanup: (#1070) - Add coverage for inserting in the middle - Remove unused function --- soroban-env-host/src/host/metered_vector.rs | 16 ---------------- soroban-env-host/src/test/vec.rs | 4 ++++ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/soroban-env-host/src/host/metered_vector.rs b/soroban-env-host/src/host/metered_vector.rs index 3a10659b8..873326778 100644 --- a/soroban-env-host/src/host/metered_vector.rs +++ b/soroban-env-host/src/host/metered_vector.rs @@ -302,22 +302,6 @@ where } } - pub fn retain_mut(&mut self, mut f: F, budget: &Budget) -> Result - where - F: FnMut(usize, &mut A) -> Result, - { - // The closure evaluation is not metered here, it is assumed to be taken care of outside. - // Here just covers the cost of cloning a Vec. - self.charge_deep_clone(budget)?; - let mut vec = Vec::with_capacity(self.len()); - for (i, v) in self.vec.iter_mut().enumerate() { - if f(i, v)? { - vec.push(v.clone()); - } - } - Self::from_vec(vec) - } - pub fn iter(&self) -> std::slice::Iter<'_, A> { self.vec.iter() } diff --git a/soroban-env-host/src/test/vec.rs b/soroban-env-host/src/test/vec.rs index 8dd7a0188..701bba517 100644 --- a/soroban-env-host/src/test/vec.rs +++ b/soroban-env-host/src/test/vec.rs @@ -227,6 +227,10 @@ fn vec_insert_and_cmp() -> Result<(), HostError> { let obj2 = host.vec_insert(obj1, 2u32.into(), 3u32.into())?; let obj_ref = host.test_vec_obj::(&[1, 2, 3])?; assert_eq!(host.obj_cmp(obj2.into(), obj_ref.into())?, 0); + + let obj3 = host.vec_insert(obj2, 2u32.into(), 4u32.into())?; + let obj_ref = host.test_vec_obj::(&[1, 2, 4, 3])?; + assert_eq!(host.obj_cmp(obj3.into(), obj_ref.into())?, 0); Ok(()) }