Skip to content

Commit

Permalink
Switch to ThinVec
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Apr 11, 2023
1 parent 345c133 commit 8850f3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions boa_engine/src/vm/call_frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -35,7 +37,7 @@ pub struct CallFrame {
pub(crate) async_generator: Option<JsObject>,

// 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 ----
Expand All @@ -55,7 +57,7 @@ impl CallFrame {
arg_count: 0,
generator_resume_kind: GeneratorResumeKind::Normal,
async_generator: None,
iterators: Vec::new(),
iterators: ThinVec::new(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion boa_engine/src/vm/opcode/control_flow/throw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
///
Expand All @@ -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 {
Expand Down

0 comments on commit 8850f3b

Please sign in to comment.