From f48d1e2be4b2dcdbc7f872b3cb7457049fffd457 Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Thu, 18 Feb 2021 10:23:57 -0800 Subject: [PATCH] Use slice::fill for filling tables. Now that `slice::fill` is stable, update the table implementation in the runtime to use it. --- crates/runtime/src/table.rs | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/crates/runtime/src/table.rs b/crates/runtime/src/table.rs index f8281c9cfa..0469c4ff39 100644 --- a/crates/runtime/src/table.rs +++ b/crates/runtime/src/table.rs @@ -180,30 +180,18 @@ impl Table { } match val { - TableElement::FuncRef(r) => { - unsafe { - self.with_funcrefs_mut(move |elements| { - let elements = elements.unwrap(); - - // TODO: replace this with slice::fill (https://github.com/rust-lang/rust/issues/70758) when stabilized - for e in &mut elements[start as usize..end as usize] { - *e = r; - } - }); - } - } - TableElement::ExternRef(r) => { - unsafe { - self.with_externrefs_mut(move |elements| { - let elements = elements.unwrap(); - - // TODO: replace this with slice::fill (https://github.com/rust-lang/rust/issues/70758) when stabilized - for e in &mut elements[start as usize..end as usize] { - *e = r.clone(); - } - }); - } - } + TableElement::FuncRef(r) => unsafe { + self.with_funcrefs_mut(move |elements| { + let elements = elements.unwrap(); + elements[start as usize..end as usize].fill(r); + }); + }, + TableElement::ExternRef(r) => unsafe { + self.with_externrefs_mut(move |elements| { + let elements = elements.unwrap(); + elements[start as usize..end as usize].fill(r); + }); + }, } Ok(())