Skip to content

Commit 56f8b11

Browse files
committed
value into vec with with_capacity
1 parent 26103b2 commit 56f8b11

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/client/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,31 +195,31 @@ impl Into<Vec<u8>> for &Value {
195195
false => vec![TSDataType::Boolean as u8, 0],
196196
},
197197
Value::Int32(v) => {
198-
let mut buff: Vec<u8> = Vec::new();
198+
let mut buff: Vec<u8> = Vec::with_capacity(4);
199199
buff.push(TSDataType::Int32 as u8);
200200
buff.append(&mut v.to_be_bytes().to_vec());
201201
buff
202202
}
203203
Value::Int64(v) => {
204-
let mut buff: Vec<u8> = Vec::new();
204+
let mut buff: Vec<u8> = Vec::with_capacity(8);
205205
buff.push(TSDataType::Int64 as u8);
206206
buff.append(&mut v.to_be_bytes().to_vec());
207207
buff
208208
}
209209
Value::Float(v) => {
210-
let mut buff: Vec<u8> = Vec::new();
210+
let mut buff: Vec<u8> = Vec::with_capacity(4);
211211
buff.push(TSDataType::Float as u8);
212212
buff.append(&mut v.to_be_bytes().to_vec());
213213
buff
214214
}
215215
Value::Double(v) => {
216-
let mut buff: Vec<u8> = Vec::new();
216+
let mut buff: Vec<u8> = Vec::with_capacity(8);
217217
buff.push(TSDataType::Double as u8);
218218
buff.append(&mut v.to_be_bytes().to_vec());
219219
buff
220220
}
221221
Value::Text(t) => {
222-
let mut buff: Vec<u8> = Vec::new();
222+
let mut buff: Vec<u8> = Vec::with_capacity(4+t.len());
223223
let len = t.len() as i32;
224224
buff.push(TSDataType::Text as u8);
225225
buff.append(&mut len.to_be_bytes().to_vec());

0 commit comments

Comments
 (0)