mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Fix performance (#3931)
* Speed up performance for converting the xml to json
This commit is contained in:
@@ -612,18 +612,23 @@ Blockly.Flyout.prototype.createBlock_ = function(blockXml) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) {
|
||||
var blockXml = null;
|
||||
// All blockInfo will have type, so check for blockxml first.
|
||||
if (blockInfo['blockxml']) {
|
||||
blockXml = Blockly.Xml.textToDom(blockInfo['blockxml']);
|
||||
var blockElement = null;
|
||||
var blockXml = blockInfo['blockxml'];
|
||||
|
||||
if (blockXml && typeof blockXml != 'string') {
|
||||
blockElement = blockXml;
|
||||
} else if (blockXml && typeof blockXml == 'string') {
|
||||
blockElement = Blockly.Xml.textToDom(blockXml);
|
||||
} else if (blockInfo['type']) {
|
||||
blockXml = Blockly.utils.xml.createElement('xml');
|
||||
blockXml.setAttribute('type', blockInfo['type']);
|
||||
blockXml.setAttribute('disabled', blockInfo['disabled']);
|
||||
} else {
|
||||
blockElement = Blockly.utils.xml.createElement('xml');
|
||||
blockElement.setAttribute('type', blockInfo['type']);
|
||||
blockElement.setAttribute('disabled', blockInfo['disabled']);
|
||||
}
|
||||
|
||||
if (!blockElement) {
|
||||
throw Error('Error: Invalid block definition. Block definition must have blockxml or type.');
|
||||
}
|
||||
return blockXml;
|
||||
return blockElement;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,15 +126,17 @@ Blockly.utils.toolbox.toolboxXmlToJson_ = function(toolboxDef) {
|
||||
continue;
|
||||
}
|
||||
var obj = {};
|
||||
obj['kind'] = child.tagName.toUpperCase();
|
||||
var tagName = child.tagName.toUpperCase();
|
||||
obj['kind'] = tagName;
|
||||
|
||||
// Store the xml for a block
|
||||
if (child.tagName.toUpperCase() == 'BLOCK') {
|
||||
obj['blockxml'] = Blockly.utils.xml.domToText(child);
|
||||
}
|
||||
// Get the contents for a category.
|
||||
if (child.tagName.toUpperCase() == 'CATEGORY') {
|
||||
if (tagName == 'BLOCK') {
|
||||
obj['blockxml'] = child;
|
||||
} else if (tagName == 'CATEGORY') {
|
||||
// Get the contents of a category
|
||||
obj['contents'] = Blockly.utils.toolbox.toolboxXmlToJson_(child);
|
||||
}
|
||||
|
||||
// Add xml attributes to object
|
||||
for (var j = 0; j < child.attributes.length; j++) {
|
||||
var attr = child.attributes[j];
|
||||
|
||||
Reference in New Issue
Block a user