Reduce Statement memory footprint

This commit is contained in:
Rerumu 2023-06-23 16:02:06 -04:00
parent 170c5c3629
commit 460363bff1
2 changed files with 14 additions and 16 deletions

View File

@ -57,7 +57,7 @@ impl From<BlockData> for LabelType {
struct StatList { struct StatList {
stack: Stack, stack: Stack,
code: Vec<Statement>, code: Vec<Statement>,
last: Option<Terminator>, last: Option<Box<Terminator>>,
block_data: BlockData, block_data: BlockData,
has_reference: bool, has_reference: bool,
@ -199,7 +199,7 @@ impl StatList {
fn set_terminator(&mut self, term: Terminator) { fn set_terminator(&mut self, term: Terminator) {
self.leak_all(); self.leak_all();
self.last = Some(term); self.last = Some(term.into());
} }
} }
@ -310,15 +310,13 @@ impl<'a> Factory<'a> {
BlockData::Forward { .. } | BlockData::Backward { .. } => Statement::Block(now.into()), BlockData::Forward { .. } | BlockData::Backward { .. } => Statement::Block(now.into()),
BlockData::If { .. } => Statement::If(If { BlockData::If { .. } => Statement::If(If {
condition: self.target.stack.pop().into(), condition: self.target.stack.pop().into(),
on_true: now.into(), on_true: Box::new(now.into()),
on_false: None, on_false: None,
}), }),
BlockData::Else { .. } => { BlockData::Else { .. } => {
if let Statement::If(v) = self.target.code.last_mut().unwrap() { let Statement::If(last) = self.target.code.last_mut().unwrap() else { unreachable!() };
v.on_false = Some(now.into());
} else { last.on_false = Some(Box::new(now.into()));
unreachable!()
}
return; return;
} }

View File

@ -887,7 +887,7 @@ pub enum Terminator {
pub struct Block { pub struct Block {
pub(crate) label_type: Option<LabelType>, pub(crate) label_type: Option<LabelType>,
pub(crate) code: Vec<Statement>, pub(crate) code: Vec<Statement>,
pub(crate) last: Option<Terminator>, pub(crate) last: Option<Box<Terminator>>,
} }
impl Block { impl Block {
@ -902,8 +902,8 @@ impl Block {
} }
#[must_use] #[must_use]
pub const fn last(&self) -> Option<&Terminator> { pub fn last(&self) -> Option<&Terminator> {
self.last.as_ref() self.last.as_deref()
} }
} }
@ -926,8 +926,8 @@ impl BrIf {
pub struct If { pub struct If {
pub(crate) condition: Box<Expression>, pub(crate) condition: Box<Expression>,
pub(crate) on_true: Block, pub(crate) on_true: Box<Block>,
pub(crate) on_false: Option<Block>, pub(crate) on_false: Option<Box<Block>>,
} }
impl If { impl If {
@ -937,13 +937,13 @@ impl If {
} }
#[must_use] #[must_use]
pub const fn on_true(&self) -> &Block { pub fn on_true(&self) -> &Block {
&self.on_true &self.on_true
} }
#[must_use] #[must_use]
pub const fn on_false(&self) -> Option<&Block> { pub fn on_false(&self) -> Option<&Block> {
self.on_false.as_ref() self.on_false.as_deref()
} }
} }