Code review feedback.

* Improve comments.
* Drop old table element *after* updating the table.
* Extract out the same `cfg_if!` to a single constant.
This commit is contained in:
Peter Huene
2021-03-08 09:04:13 -08:00
parent 8e51aefb2c
commit 7a93132ffa
4 changed files with 19 additions and 25 deletions

View File

@@ -372,11 +372,13 @@ impl Table {
}
}
fn set_raw(ty: TableElementType, e: &mut *mut u8, val: TableElement) {
fn set_raw(ty: TableElementType, elem: &mut *mut u8, val: TableElement) {
unsafe {
// Drop the existing element
let _ = TableElement::from_raw(ty, *e);
*e = val.into_raw();
let old = *elem;
*elem = val.into_raw();
// Drop the old element
let _ = TableElement::from_raw(ty, old);
}
}