Skip to content

Commit

Permalink
removing bounds checking
Browse files Browse the repository at this point in the history
  • Loading branch information
fabi321 committed Dec 28, 2023
1 parent 15f0f73 commit b1cbf6a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::framebuffer::FrameBuffer;
use const_format::formatcp;
use log::{info, warn};
use std::simd::{num::SimdUint, u32x8, Simd};
use std::slice::from_raw_parts;
use std::sync::Arc;
use tokio::io::AsyncWriteExt;

Expand Down Expand Up @@ -91,7 +92,7 @@ pub async fn parse_pixelflut_commands(
last_byte_parsed = i + 6;
i += 7; // We can advance one byte more than normal as we use continue and therefore not get incremented at the end of the loop

let rgba: u32 = simd_unhex(&buffer[i - 7..i + 1]);
let rgba: u32 = simd_unhex(unsafe { from_raw_parts(buffer.as_ptr().add(i - 7), 8) });

fb.set(x, y, rgba & 0x00ff_ffff);
continue;
Expand All @@ -103,7 +104,7 @@ pub async fn parse_pixelflut_commands(
last_byte_parsed = i + 8;
i += 9; // We can advance one byte more than normal as we use continue and therefore not get incremented at the end of the loop

let rgba: u32 = simd_unhex(&buffer[i - 9..i - 1]);
let rgba: u32 = simd_unhex(unsafe { from_raw_parts(buffer.as_ptr().add(i - 9), 8) });

fb.set(x, y, rgba & 0x00ff_ffff);
continue;
Expand All @@ -113,7 +114,7 @@ pub async fn parse_pixelflut_commands(
last_byte_parsed = i + 8;
i += 9; // We can advance one byte more than normal as we use continue and therefore not get incremented at the end of the loop

let rgba = simd_unhex(&buffer[i - 9..i - 1]);
let rgba = simd_unhex(unsafe { from_raw_parts(buffer.as_ptr().add(i - 9), 8) });

let alpha = (rgba >> 24) & 0xff;

Expand All @@ -140,7 +141,7 @@ pub async fn parse_pixelflut_commands(
last_byte_parsed = i + 2;
i += 3; // We can advance one byte more than normal as we use continue and therefore not get incremented at the end of the loop

let base = simd_unhex(&buffer[i - 3..i + 5]) & 0xff;
let base = simd_unhex(unsafe { from_raw_parts(buffer.as_ptr().add(i - 3), 8) }) & 0xff;

let rgba: u32 = base << 16 | base << 8 | base;

Expand Down

0 comments on commit b1cbf6a

Please sign in to comment.