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.
This commit is contained in:
Mahmoud Al-Qudsi 2024-06-01 12:59:37 -05:00
parent edd6533a14
commit 2e52d51af2
3 changed files with 7 additions and 7 deletions

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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<Box<BlockData>>,
/// 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<Arc<WString>>,
@ -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<NonZeroU16>,
/// 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,