From 2e52d51af29806d7d614e1cb864600b4a394db06 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 1 Jun 2024 12:59:37 -0500 Subject: [PATCH] Convert Block::event_blocks to a bool We only increment it and check if it's non-zero, we never decrement or check the actual count. As such, change it to a bool and bring the size of `Block` down from 32 to 24 bytes. --- src/builtins/block.rs | 2 +- src/event.rs | 2 +- src/parser.rs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/builtins/block.rs b/src/builtins/block.rs index 3d3071af1..2e2ad7e0b 100644 --- a/src/builtins/block.rs +++ b/src/builtins/block.rs @@ -139,7 +139,7 @@ pub fn block(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Op }; if have_block { - parser.block_at_index_mut(block_idx).unwrap().event_blocks += 1; + parser.block_at_index_mut(block_idx).unwrap().event_blocks |= true; } else { parser.global_event_blocks.fetch_add(1, Ordering::Relaxed); } diff --git a/src/event.rs b/src/event.rs index 353a6fd9b..6c4fede68 100644 --- a/src/event.rs +++ b/src/event.rs @@ -267,7 +267,7 @@ impl Event { /// Test if specified event is blocked. fn is_blocked(&self, parser: &Parser) -> bool { for block in parser.blocks().iter().rev() { - if block.event_blocks != 0 { + if block.event_blocks { return true; } } diff --git a/src/parser.rs b/src/parser.rs index effd3df74..b50a02f08 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -61,6 +61,9 @@ pub enum BlockData { /// block_t represents a block of commands. #[derive(Default)] pub struct Block { + /// Type of block. + block_type: BlockType, + /// [`BlockType`]-specific data. /// /// Ideally this would be coalesced into `BlockType` but we currently require that to implement @@ -70,8 +73,8 @@ pub struct Block { /// we store them in a `Box` to reduce the size of the `Block` itself. pub data: Option>, - /// List of event blocks. - pub event_blocks: u64, + /// Pseudo-counter of event blocks + pub event_blocks: bool, /// Name of the file that created this block pub src_filename: Option>, @@ -84,9 +87,6 @@ pub struct Block { /// This will saturate at the 65,535th line of a single fish script. I think that's ok! pub src_lineno: Option, - /// Type of block. - block_type: BlockType, - /// Whether we should pop the environment variable stack when we're popped off of the block /// stack. pub wants_pop_env: bool,