Skip to content

Commit a433c0f

Browse files
committed
split: Reduce malloc
1 parent de5c827 commit a433c0f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/uu/split/src/split.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ where
11561156
out_files = OutFiles::init(num_chunks, settings, false)?;
11571157
}
11581158

1159-
let buf = &mut Vec::new();
1159+
let mut buf = Vec::with_capacity((chunk_size_base + 1) as usize);
11601160
for i in 1_u64..=num_chunks {
11611161
let chunk_size = chunk_size_base + (chunk_size_reminder > i - 1) as u64;
11621162
buf.clear();
@@ -1175,7 +1175,7 @@ where
11751175
}
11761176
};
11771177

1178-
let n_bytes_read = reader.by_ref().take(limit).read_to_end(buf);
1178+
let n_bytes_read = reader.by_ref().take(limit).read_to_end(&mut buf);
11791179

11801180
match n_bytes_read {
11811181
Ok(n_bytes) => {
@@ -1191,13 +1191,13 @@ where
11911191

11921192
if let Some(chunk_number) = kth_chunk {
11931193
if i == chunk_number {
1194-
stdout_writer.write_all(buf)?;
1194+
stdout_writer.write_all(&buf)?;
11951195
break;
11961196
}
11971197
} else {
11981198
let idx = (i - 1) as usize;
11991199
let writer = out_files.get_writer(idx, settings)?;
1200-
writer.write_all(buf)?;
1200+
writer.write_all(&buf)?;
12011201
}
12021202
} else {
12031203
break;

0 commit comments

Comments
 (0)