Performance improvements for workspace clear and load

This commit is contained in:
Rachel Fenichel
2018-05-17 11:05:18 -07:00
parent 8ead7dabd8
commit df7f534ad6
3 changed files with 64 additions and 25 deletions

View File

@@ -115,6 +115,13 @@ Blockly.Workspace = function(opt_options) {
*/
Blockly.Workspace.prototype.rendered = false;
/**
* Returns `true` if the workspace is currently in the process of a bulk clear.
* @type {boolean}
* @package
*/
Blockly.Workspace.prototype.isClearing = false;
/**
* Maximum number of undo events in stack. `0` turns off undo, `Infinity` sets it to unlimited.
* @type {number}
@@ -264,22 +271,27 @@ Blockly.Workspace.prototype.getAllBlocks = function(ordered) {
* Dispose of all blocks and comments in workspace.
*/
Blockly.Workspace.prototype.clear = function() {
var existingGroup = Blockly.Events.getGroup();
if (!existingGroup) {
Blockly.Events.setGroup(true);
}
while (this.topBlocks_.length) {
this.topBlocks_[0].dispose();
}
while (this.topComments_.length) {
this.topComments_[this.topComments_.length - 1].dispose();
}
if (!existingGroup) {
Blockly.Events.setGroup(false);
}
this.variableMap_.clear();
if (this.potentialVariableMap_) {
this.potentialVariableMap_.clear();
this.isClearing = true;
try {
var existingGroup = Blockly.Events.getGroup();
if (!existingGroup) {
Blockly.Events.setGroup(true);
}
while (this.topBlocks_.length) {
this.topBlocks_[0].dispose();
}
while (this.topComments_.length) {
this.topComments_[this.topComments_.length - 1].dispose();
}
if (!existingGroup) {
Blockly.Events.setGroup(false);
}
this.variableMap_.clear();
if (this.potentialVariableMap_) {
this.potentialVariableMap_.clear();
}
} finally {
this.isClearing = false;
}
};