Remove a bunch of unnecessary allocations and copies
auto merge of #6829 : dotdash/rust/allocs, r=sanxiyn