Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/api/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ impl Table {
/// Grows the size of this table by `delta` more elements, initialization
/// all new elements to `init`.
///
/// Returns the previous size of this table if successful.
///
/// # Errors
///
/// Returns an error if the table cannot be grown by `delta`, for example
Expand All @@ -381,8 +383,7 @@ impl Table {
let item = into_checked_anyfunc(init, &self.instance.store)?;
if let Some(len) = self.instance.table_grow(index, delta) {
for i in 0..delta {
let i = len - (delta - i);
set_table_item(&self.instance, index, i, item.clone())?;
set_table_item(&self.instance, index, len + i, item.clone())?;
}
Ok(len)
} else {
Expand Down
5 changes: 3 additions & 2 deletions crates/runtime/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl Table {
/// Returns `None` if table can't be grown by the specified amount
/// of elements.
pub fn grow(&self, delta: u32) -> Option<u32> {
let new_len = match self.size().checked_add(delta) {
let size = self.size();
Copy link
Copy Markdown
Member

@peterhuene peterhuene May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should we document what this function returns in the Some case?

let new_len = match size.checked_add(delta) {
Some(len) => {
if let Some(max) = self.maximum {
if len > max {
Expand All @@ -63,7 +64,7 @@ impl Table {
usize::try_from(new_len).unwrap(),
VMCallerCheckedAnyfunc::default(),
);
Some(new_len)
Some(size)
}

/// Get reference to the specified element.
Expand Down