Skip to content

Commit

Permalink
Fix review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisduerr committed Jan 9, 2025
1 parent f7a10b2 commit 1ad25bc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl<T: Timeout> Processor<T> {
H: Handler,
{
let mut processed = 0;
while processed < bytes.len() {
while processed != bytes.len() {
if self.state.sync_state.timeout.pending_timeout() {
processed += self.advance_sync(handler, &bytes[processed..]);
} else {
Expand Down Expand Up @@ -345,7 +345,7 @@ impl<T: Timeout> Processor<T> {
// function checks for BSUs in reverse.
Some(bsu_offset) => {
let new_len = self.state.sync_state.buffer.len() - bsu_offset;
self.state.sync_state.buffer.rotate_left(bsu_offset);
self.state.sync_state.buffer.copy_within(bsu_offset.., 0);
self.state.sync_state.buffer.truncate(new_len);
},
// Report mode and clear state if no new BSU is present.
Expand Down
4 changes: 2 additions & 2 deletions src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::mem;

#[allow(dead_code)]
#[repr(u8)]
#[derive(Debug, Default, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Default, Copy, Clone)]
pub enum State {
CsiEntry,
CsiIgnore,
Expand All @@ -25,7 +25,7 @@ pub enum State {
// NOTE: Removing the unused actions prefixed with `_` will reduce performance.
#[allow(dead_code)]
#[repr(u8)]
#[derive(Debug, Clone, Copy)]
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum Action {
None,
_Clear,
Expand Down
19 changes: 10 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<const OSC_RAW_BUF_SIZE: usize> Parser<OSC_RAW_BUF_SIZE> {
i += self.advance_partial_utf8(performer, bytes);
}

while i < bytes.len() {
while i != bytes.len() {
match self.state {
State::Ground => i += self.advance_ground(performer, &bytes[i..]),
_ => {
Expand Down Expand Up @@ -151,11 +151,11 @@ impl<const OSC_RAW_BUF_SIZE: usize> Parser<OSC_RAW_BUF_SIZE> {
let mut i = 0;

// Handle partial codepoints from previous calls to `advance`.
if self.partial_utf8_len > 0 {
if self.partial_utf8_len != 0 {
i += self.advance_partial_utf8(performer, bytes);
}

while i < bytes.len() && !performer.terminated() {
while i != bytes.len() && !performer.terminated() {
match self.state {
State::Ground => i += self.advance_ground(performer, &bytes[i..]),
_ => {
Expand All @@ -178,7 +178,7 @@ impl<const OSC_RAW_BUF_SIZE: usize> Parser<OSC_RAW_BUF_SIZE> {
where
P: Perform,
{
if matches!(state, State::Anywhere) {
if state == State::Anywhere {
self.perform_action(performer, action, byte);
return;
}
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<const OSC_RAW_BUF_SIZE: usize> Parser<OSC_RAW_BUF_SIZE> {
_ => (),
}

if matches!(action, Action::None) {
if action == Action::None {
match state {
State::CsiEntry | State::DcsEntry | State::Escape => self.reset_params(),
State::DcsPassthrough => {
Expand Down Expand Up @@ -425,10 +425,10 @@ impl<const OSC_RAW_BUF_SIZE: usize> Parser<OSC_RAW_BUF_SIZE> {
None => {
// Process bytes cut off by the buffer end.
let extra_bytes = num_bytes - valid_bytes;
for i in 0..extra_bytes {
self.partial_utf8[self.partial_utf8_len + i] = bytes[valid_bytes + i];
}
self.partial_utf8_len += extra_bytes;
let partial_len = self.partial_utf8_len + extra_bytes;
self.partial_utf8[self.partial_utf8_len..partial_len]
.copy_from_slice(&bytes[valid_bytes..valid_bytes + extra_bytes]);
self.partial_utf8_len = partial_len;
num_bytes
},
}
Expand Down Expand Up @@ -573,6 +573,7 @@ pub trait Perform {
///
/// This is checked after every parsed byte, so no expensive computation
/// should take place in this function.
#[inline(always)]
fn terminated(&self) -> bool {
false
}
Expand Down
2 changes: 1 addition & 1 deletion src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use vte_generate_state_changes::generate_state_changes;
use crate::definitions::{pack, Action, State};

// Generate state changes at compile-time
pub static STATE_CHANGES: [[u8; 256]; 13] = state_changes();
pub const STATE_CHANGES: [[u8; 256]; 13] = state_changes();
generate_state_changes!(state_changes, {
Escape {
0x00..=0x17 => (Anywhere, Execute),
Expand Down

0 comments on commit 1ad25bc

Please sign in to comment.