From 8850f3b55e9969c924b30ec78395b4d6d5220826 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:27:00 +0200 Subject: [PATCH] Switch to ThinVec --- boa_engine/src/vm/call_frame/mod.rs | 12 +++++++----- boa_engine/src/vm/opcode/control_flow/throw.rs | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/boa_engine/src/vm/call_frame/mod.rs b/boa_engine/src/vm/call_frame/mod.rs index 0dd261318b7..7e69fae3fcc 100644 --- a/boa_engine/src/vm/call_frame/mod.rs +++ b/boa_engine/src/vm/call_frame/mod.rs @@ -2,14 +2,16 @@ //! //! This module will provides everything needed to implement the `CallFrame` -use crate::{object::JsObject, vm::CodeBlock}; -use boa_gc::{Finalize, Gc, Trace}; - mod abrupt_record; mod env_stack; +use crate::{object::JsObject, vm::CodeBlock}; +use boa_gc::{Finalize, Gc, Trace}; +use thin_vec::ThinVec; + pub(crate) use abrupt_record::AbruptCompletionRecord; pub(crate) use env_stack::EnvStackEntry; + /// A `CallFrame` holds the state of a function call. #[derive(Clone, Debug, Finalize, Trace)] pub struct CallFrame { @@ -35,7 +37,7 @@ pub struct CallFrame { pub(crate) async_generator: Option, // Iterators and their `[[Done]]` flags that must be closed when an abrupt completion is thrown. - pub(crate) iterators: Vec<(JsObject, bool)>, + pub(crate) iterators: ThinVec<(JsObject, bool)>, } /// ---- `CallFrame` creation methods ---- @@ -55,7 +57,7 @@ impl CallFrame { arg_count: 0, generator_resume_kind: GeneratorResumeKind::Normal, async_generator: None, - iterators: Vec::new(), + iterators: ThinVec::new(), } } diff --git a/boa_engine/src/vm/opcode/control_flow/throw.rs b/boa_engine/src/vm/opcode/control_flow/throw.rs index 64723e6e0a8..85e12c62e97 100644 --- a/boa_engine/src/vm/opcode/control_flow/throw.rs +++ b/boa_engine/src/vm/opcode/control_flow/throw.rs @@ -3,6 +3,7 @@ use crate::{ vm::{call_frame::AbruptCompletionRecord, opcode::Operation, CompletionType}, Context, JsError, JsNativeError, JsResult, }; +use thin_vec::ThinVec; /// `Throw` implements the Opcode Operation for `Opcode::Throw` /// @@ -23,7 +24,7 @@ impl Operation for Throw { }; // Close all iterators that are still open. - let mut iterators = Vec::new(); + let mut iterators = ThinVec::new(); std::mem::swap(&mut iterators, &mut context.vm.frame_mut().iterators); for (iterator, done) in iterators { if done {