coreenhancementhelp wantedpriority-medium
Repository metrics
- Stars
- (37 stars)
- PR merge metrics
- (PR metrics pending)
Description
The WasmReader is currently used to (1) store a reference to the WASM bytecode and (2) an index for the current location in the bytecode. This issue proposes a refactor for the WasmReader. Its replacement will be a more generic WasmCursor that is just a newtype wrapper around (2):
/// Newtype for an index into the WASM bytecode
pub struct WasmCursor(pub usize);
impl WasmCursor {
/// Its methods now need to specify the WASM bytecode as an additional argument
pub fn peek_u8(&self, wasm: &[u8]) -> Result<u8> { .. }
}
Pros
- Better separation of responsibilities: The cursor should not need store the bytecode. This also comes with the removal of the lifetime annotation on the struct
- Less memory usage: 1 * usize instead of 3 * usize. In theory, even a
u32would suffice, as WASM only allows for 32-bit indexing. WasmCursorcan be used as the program counter / instruction index
Cons
- Now the WASM bytecode has to be specified as an additional argument for most methods
- More overhead for the developer, who now has to provide 1 additional argument for every method call