mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Reduce explicit Block
state
This doesn't have any effect on the size of the struct (due to alignment requirements and padding) but reduces the complexity by turning Block::wants_pop_env into an emergent property dependent on the type rather than something we have to manually manage.
This commit is contained in:
parent
2e52d51af2
commit
ac40807309
1 changed files with 6 additions and 9 deletions
|
@ -66,9 +66,6 @@ pub struct Block {
|
|||
|
||||
/// [`BlockType`]-specific data.
|
||||
///
|
||||
/// Ideally this would be coalesced into `BlockType` but we currently require that to implement
|
||||
/// `Copy`, so now we have to awkwardly deal with a discriminant stored separately.
|
||||
///
|
||||
/// None of these data fields are accessed on a regular basis (only for shell introspection), so
|
||||
/// we store them in a `Box` to reduce the size of the `Block` itself.
|
||||
pub data: Option<Box<BlockData>>,
|
||||
|
@ -86,10 +83,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>,
|
||||
|
||||
/// Whether we should pop the environment variable stack when we're popped off of the block
|
||||
/// stack.
|
||||
pub wants_pop_env: bool,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
|
@ -97,6 +90,11 @@ impl Block {
|
|||
pub fn data(&self) -> Option<&BlockData> {
|
||||
self.data.as_deref()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn wants_pop_env(&self) -> bool {
|
||||
self.typ() != BlockType::top
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BlockType {
|
||||
|
@ -837,7 +835,6 @@ impl Parser {
|
|||
if block.typ() != BlockType::top {
|
||||
let new_scope = block.typ() == BlockType::function_call { shadows: true };
|
||||
self.vars().push(new_scope);
|
||||
block.wants_pop_env = true;
|
||||
}
|
||||
|
||||
let mut block_list = self.block_list.borrow_mut();
|
||||
|
@ -852,7 +849,7 @@ impl Parser {
|
|||
assert!(expected == block_list.len() - 1);
|
||||
block_list.pop().unwrap()
|
||||
};
|
||||
if block.wants_pop_env {
|
||||
if block.wants_pop_env() {
|
||||
self.vars().pop();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue