Use Vec::with_capacity (#891)

Co-authored-by: Matthew Martin <phy1729@Matthews-Mac-mini.local>
This commit is contained in:
Matthew Martin
2026-02-17 11:55:34 -06:00
committed by GitHub
parent 9b6c4cee0b
commit 062db87572
4 changed files with 5 additions and 5 deletions

View File

@@ -102,7 +102,7 @@ pub trait GenericFramebuffer: Send + 'static {
resized_img = img;
}
let img_rgba8 = resized_img.as_rgba8().unwrap();
let mut buf = Vec::new();
let mut buf = Vec::with_capacity((height * width).try_into().unwrap());
for y in 0..height {
for x in 0..width {
let px = img_rgba8.get_pixel(x, y);
@@ -145,7 +145,7 @@ pub trait GenericFramebuffer: Send + 'static {
async fn draw_patterned_line(&mut self, color: Color, height: u32, pattern: LinePattern) {
let width = self.dimensions().width;
let mut buffer = Vec::new();
let mut buffer = Vec::with_capacity((height * width).try_into().unwrap());
for _row in 0..height {
for col in 0..width {

View File

@@ -23,7 +23,7 @@ impl GenericFramebuffer for Framebuffer {
}
async fn write_buffer(&mut self, buffer: Vec<(u8, u8, u8)>) {
let mut raw_buffer = Vec::new();
let mut raw_buffer = Vec::with_capacity(buffer.len() * 2);
for (r, g, b) in buffer {
let mut rgb565: u16 = (r as u16 & 0b11111000) << 8;
rgb565 |= (g as u16 & 0b11111100) << 3;

View File

@@ -50,7 +50,7 @@ impl GenericFramebuffer for Framebuffer {
rop: 0,
};
let mut raw_buffer = Vec::new();
let mut raw_buffer = Vec::with_capacity(buffer.len() * 2);
for (r, g, b) in buffer {
let mut rgb565: u16 = (r as u16 & 0b11111000) << 8;
rgb565 |= (g as u16 & 0b11111100) << 3;

View File

@@ -28,7 +28,7 @@ impl GenericFramebuffer for Framebuffer {
}
async fn write_buffer(&mut self, buffer: Vec<(u8, u8, u8)>) {
let mut raw_buffer = Vec::new();
let mut raw_buffer = Vec::with_capacity(buffer.len() * 2);
for (r, g, b) in buffer {
let mut rgb565: u16 = (r as u16 & 0b11111000) << 8;
rgb565 |= (g as u16 & 0b11111100) << 3;