The purpose of Env was to avoid copying bytes from a slice &[u8] into a Vec and then again from a Vec into a Java byte[] or TypeScript Buffer. However, that's only relevant if the operation being bridged didn't already produce a Vec. Additionally, if it produces a slice but that slice is kept alive by one of the parameters, it can just be returned directly. The only place where we were actually saving a copy was when the function looked like this:
let intermediate = input.derive_intermediate();
let result: &[u8] = intermediate.access_result();
Ok(env.buffer(result))
And in practice, there were only two of these, one of which was used only for testing. That doesn't justify the complexity of Env. Look how much code got deleted!
This PR also renames bridge_get_bytearray to bridge_get_buffer to bring it in line with bridge_fn_buffer. The new bridge_get_buffer requires you to specify the return type so that slices can be returned.
The purpose of Env was to avoid copying bytes from a slice
&[u8]
into a Vec and then again from a Vec into a Javabyte[]
or TypeScript Buffer. However, that's only relevant if the operation being bridged didn't already produce a Vec. Additionally, if it produces a slice but that slice is kept alive by one of the parameters, it can just be returned directly. The only place where we were actually saving a copy was when the function looked like this:And in practice, there were only two of these, one of which was used only for testing. That doesn't justify the complexity of Env. Look how much code got deleted!
This PR also renames
bridge_get_bytearray
tobridge_get_buffer
to bring it in line withbridge_fn_buffer
. The newbridge_get_buffer
requires you to specify the return type so that slices can be returned.