From 23743dbd59349180978785bc4524129e9bf1025f Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 15 Jul 2024 04:31:47 +0000 Subject: [PATCH] perf(semantic): do not record ast nodes for cfg if cfg disabled (#4263) Control flow graph builder records AST node IDs in a temp structure `ast_node_records`. Disable this if CFG is disabled. --- crates/oxc_semantic/src/builder.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index bffe34e63b445..83138573480cf 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -250,18 +250,26 @@ impl<'a> SemanticBuilder<'a> { } fn record_ast_nodes(&mut self) { - self.ast_node_records.push(AstNodeId::dummy()); + if self.cfg.is_some() { + self.ast_node_records.push(AstNodeId::dummy()); + } } #[allow(clippy::unnecessary_wraps)] fn retrieve_recorded_ast_node(&mut self) -> Option { - Some(self.ast_node_records.pop().expect("there is no ast node record to stop.")) + if self.cfg.is_some() { + Some(self.ast_node_records.pop().expect("there is no ast node record to stop.")) + } else { + None + } } fn record_ast_node(&mut self) { - if let Some(record) = self.ast_node_records.last_mut() { - if *record == AstNodeId::dummy() { - *record = self.current_node_id; + if self.cfg.is_some() { + if let Some(record) = self.ast_node_records.last_mut() { + if *record == AstNodeId::dummy() { + *record = self.current_node_id; + } } } }