Closed tomjridge closed 4 years ago
The reason is that the read
function needs to return both the position it read to and the resulting value. We could return both of these values by wrapping them in a tuple, but that incurs an extra allocation. Storing the int into the ref using side-effect lets us avoid that allocation.
There is no corresponding problem with write
because write only needs to return one thing, so we use the simpler interface.
Thank you @aalekseyev ! I had not considered the cost of the extra allocation.
Question as title. I don't mind, I just thought it looked a bit odd. What was the reasoning behind making the interfaces different in this way?
Thanks