Update Table::grow's return to be the previous size (#1653)

* Update `Table::grow`'s return to be the previous size

This brings it in line with `Memory::grow` and the `table.grow`
instruction which return the size of the table previously, not the size
of the table currently.

* Comment successful return
This commit is contained in:
Alex Crichton
2020-05-05 12:03:31 -05:00
committed by GitHub
parent fa54422854
commit 8e934e6762
2 changed files with 8 additions and 5 deletions

View File

@@ -44,9 +44,11 @@ impl Table {
/// Grow table by the specified amount of elements.
///
/// Returns `None` if table can't be grown by the specified amount
/// of elements.
/// of elements. Returns the previous size of the table if growth is
/// successful.
pub fn grow(&self, delta: u32) -> Option<u32> {
let new_len = match self.size().checked_add(delta) {
let size = self.size();
let new_len = match size.checked_add(delta) {
Some(len) => {
if let Some(max) = self.maximum {
if len > max {
@@ -63,7 +65,7 @@ impl Table {
usize::try_from(new_len).unwrap(),
VMCallerCheckedAnyfunc::default(),
);
Some(new_len)
Some(size)
}
/// Get reference to the specified element.