Skip to content

Commit

Permalink
inline cache prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Apr 8, 2023
1 parent 5020d03 commit 604489f
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions boa_engine/src/vm/opcode/get/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Operation for GetPropertyByName {
};

if slot_attributes & SlotAttributes::NOT_CACHABLE.bits() != 0 {
// TODO: passible optimization, inline sym into bytecode, since it fits in the shape pointer.
let ic = &context.vm.frame().code_block.ic[ic_index as usize];
let name = context.vm.frame().code_block.names[ic.literal_index as usize];
let key: PropertyKey = context.interner().resolve_expect(name.sym()).utf16().into();
Expand Down Expand Up @@ -70,21 +71,12 @@ impl Operation for GetPropertyByName {

// Check if it can be cached.
let shape = object.borrow().properties().shape.clone();
let (slot, result) = if let Some(mut slot) = shape.lookup(&key) {
let slot = if let Some(mut slot) = shape.lookup(&key) {
slot.attributes |= SlotAttributes::DIRECT;
let result = object.borrow().properties().storage[slot.index as usize].clone()
(slot, result)
} else if let Some(prototype) = shape.prototype()
{
let Some(slot) = prototype.borrow().properties().shape.lookup(&key) else {
let result = object.__get__(&key, value, context)?;
context.vm.push(result);
return Ok(CompletionType::Normal);
};

slot.attributes |= SlotAttributes::PROTOTYPE;

(slot, result)
slot
} else if let Some(mut slot) = shape.prototype().and_then(|prototype| prototype.borrow().properties().shape.lookup(&key)) {
slot.attributes.set(SlotAttributes::DIRECT, false);
slot
} else {
let result = object.__get__(&key, value, context)?;
context.vm.push(result);
Expand Down

0 comments on commit 604489f

Please sign in to comment.