virtio-devices: vsock: Fix slow vector initialization

warning: slow zero-filling initialization
   --> virtio-devices/src/vsock/csm/txbuf.rs:218:9
    |
216 |         let mut tmp: Vec<u8> = Vec::new();
    |                                ---------- help: consider replacing this with: `vec![0; TxBuf::SIZE - 2]`
217 |
218 |         tmp.resize(TxBuf::SIZE - 2, 0);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization
    = note: `#[warn(clippy::slow_vector_initialization)]` on by default

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This commit is contained in:
Rob Bradford 2023-08-22 10:56:28 +01:00 committed by Rob Bradford
parent 4d8dacec5e
commit 05a86d892e

View File

@ -213,9 +213,7 @@ mod tests {
fn test_push_wrap() { fn test_push_wrap() {
let mut txbuf = TxBuf::new(); let mut txbuf = TxBuf::new();
let mut sink = TestSink::new(); let mut sink = TestSink::new();
let mut tmp: Vec<u8> = Vec::new(); let tmp: Vec<u8> = vec![0; TxBuf::SIZE - 2];
tmp.resize(TxBuf::SIZE - 2, 0);
txbuf.push(tmp.as_slice()).unwrap(); txbuf.push(tmp.as_slice()).unwrap();
txbuf.flush_to(&mut sink).unwrap(); txbuf.flush_to(&mut sink).unwrap();
sink.clear(); sink.clear();