mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
parent
5b9dc4df77
commit
d04d6b2c6a
8 changed files with 198 additions and 65 deletions
|
@ -4,6 +4,7 @@ const xmlEscape = require('../util/xml-escape');
|
|||
const MonitorRecord = require('./monitor-record');
|
||||
const Clone = require('../util/clone');
|
||||
const {Map} = require('immutable');
|
||||
const BlocksExecuteCache = require('./blocks-execute-cache');
|
||||
|
||||
/**
|
||||
* @fileoverview
|
||||
|
@ -47,7 +48,14 @@ class Blocks {
|
|||
* Cache procedure definitions by block id
|
||||
* @type {object.<string, ?string>}
|
||||
*/
|
||||
procedureDefinitions: {}
|
||||
procedureDefinitions: {},
|
||||
|
||||
/**
|
||||
* A cache for execute to use and store on. Only available to
|
||||
* execute.
|
||||
* @type {object.<string, object>}
|
||||
*/
|
||||
_executeCached: {}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -359,6 +367,7 @@ class Blocks {
|
|||
this._cache.inputs = {};
|
||||
this._cache.procedureParamNames = {};
|
||||
this._cache.procedureDefinitions = {};
|
||||
this._cache._executeCached = {};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -435,7 +444,7 @@ class Blocks {
|
|||
const isSpriteSpecific = optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
|
||||
optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific;
|
||||
block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null;
|
||||
|
||||
|
||||
if (wasMonitored && !block.isMonitored) {
|
||||
optRuntime.requestRemoveMonitor(block.id);
|
||||
} else if (!wasMonitored && block.isMonitored) {
|
||||
|
@ -859,4 +868,31 @@ class Blocks {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A private method shared with execute to build an object containing the block
|
||||
* information execute needs and that is reset when other cached Blocks info is
|
||||
* reset.
|
||||
* @param {Blocks} blocks Blocks containing the expected blockId
|
||||
* @param {string} blockId blockId for the desired execute cache
|
||||
* @return {object} execute cache object
|
||||
*/
|
||||
BlocksExecuteCache.getCached = function (blocks, blockId) {
|
||||
const block = blocks.getBlock(blockId);
|
||||
if (typeof block === 'undefined') return null;
|
||||
let cached = blocks._cache._executeCached[blockId];
|
||||
if (typeof cached !== 'undefined') {
|
||||
return cached;
|
||||
}
|
||||
|
||||
cached = {
|
||||
_initialized: false,
|
||||
opcode: blocks.getOpcode(block),
|
||||
fields: blocks.getFields(block),
|
||||
inputs: blocks.getInputs(block),
|
||||
mutation: blocks.getMutation(block)
|
||||
};
|
||||
blocks._cache._executeCached[blockId] = cached;
|
||||
return cached;
|
||||
};
|
||||
|
||||
module.exports = Blocks;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue