From 716c907dc2cd5c1289a60889c28d778464cd9fa8 Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 26 Nov 2015 18:36:28 +0100 Subject: [PATCH] when rewriting the buffer, reserve enougth space --- src/rlp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rlp.rs b/src/rlp.rs index 03a10348c..3e29b783b 100644 --- a/src/rlp.rs +++ b/src/rlp.rs @@ -459,6 +459,8 @@ impl BasicEncoder { fn insert_list_len_at_pos(&mut self, len: usize, pos: usize) -> () { // new bytes let mut res: Vec = vec![]; + // reserve a space equal at least current space + space for length + res.reserve(self.bytes.len() + 1); { let (before_slice, after_slice) = self.bytes.split_at(pos); res.extend(before_slice);