Commits

Jorge C. Leitao authored a3eb4a9d454
ARROW-10561: [Rust] Simplified Buffer's `write` and `write_bytes` and fixed undefined behavior This PR addresses a major issue on builders and 3 small issues on `MutableBuffer`: 1. [major] fixes undefined behavior due to a incorrect pointer arithmetic in `set_bits_raw`, causing a bench to segfault 1. `write_bytes` is incorrect, as it double-increments `len`: the length is incremented both on `self.write` and also by `write_bytes` itself. This leads to more allocations than necessary. 2. `write` is implemented from the trait `io::Write`. However, this trait is suitable for fallible IO operations. In the case of a write to memory, it isn't really fallible because we can always call `reserve` to allocate more space. 3. `write` and `write_bytes` are really similar. This PR replaces both `write_bytes` and `write` by `extend_from_slice` (inspired by [`Vec::extend_from_slice`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.extend_from_slice)) that checks the available capacity and reserves more if necessary. This has the same or better performance than `write`, as it performs a single comparison per call. Closes #8645 from jorgecarleitao/buffer_write Authored-by: Jorge C. Leitao <jorgecarleitao@gmail.com> Signed-off-by: Jorge C. Leitao <jorgecarleitao@gmail.com>