Replace map with for loop for perf. reasons (as this method is likely to be called thousands of times).

This commit is contained in:
kangax 2011-02-09 01:03:04 -05:00
parent afb841e085
commit ca11620451
5 changed files with 27 additions and 27 deletions

36
dist/all.js vendored
View file

@ -2788,7 +2788,8 @@ fabric.util.animate = animate;
}
}
elements.map(function(el, index) {
for (var index = 0, el, len = elements.length; index < len; index++) {
el = elements[index];
var klass = fabric[capitalize(el.tagName)];
if (klass && klass.fromElement) {
try {
@ -2812,7 +2813,7 @@ fabric.util.animate = animate;
else {
checkIfDone();
}
});
}
};
/**
@ -2892,18 +2893,19 @@ fabric.util.animate = animate;
*/
fabric.parseSVGDocument = (function() {
var reAllowedSVGTagNames = /^(path|circle|polygon|polyline|ellipse|rect|line|image)$/,
reNum = '(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)',
reViewBoxAttrValue = new RegExp(
'^' +
'\\s*(' + reNum + '+)\\s*,?' +
'\\s*(' + reNum + '+)\\s*,?' +
'\\s*(' + reNum + '+)\\s*,?' +
'\\s*(' + reNum + '+)\\s*' +
'$'
);
var reAllowedSVGTagNames = /^(path|circle|polygon|polyline|ellipse|rect|line|image)$/;
var reNum = '(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)';
var reViewBoxAttrValue = new RegExp(
'^' +
'\\s*(' + reNum + '+)\\s*,?' +
'\\s*(' + reNum + '+)\\s*,?' +
'\\s*(' + reNum + '+)\\s*,?' +
'\\s*(' + reNum + '+)\\s*' +
'$'
);
function hasAncestorWithNodeName(element, nodeName) {
while (element && (element = element.parentNode)) {
@ -8737,10 +8739,8 @@ fabric.util.animate = animate;
* @return {fabric.Path} Instance of fabric.Path
*/
fabric.Path.fromElement = function(element, options) {
var parsedAttributes = fabric.parseAttributes(element, fabric.Path.ATTRIBUTE_NAMES),
path = parsedAttributes.d;
delete parsedAttributes.d;
return new fabric.Path(path, extend(parsedAttributes, options));
var parsedAttributes = fabric.parseAttributes(element, fabric.Path.ATTRIBUTE_NAMES);
return new fabric.Path(parsedAttributes.d, parsedAttributes ? extend(parsedAttributes, options) : undefined);
};
})(this);

View file

@ -331,8 +331,9 @@
callback(instances);
}
}
elements.map(function(el, index) {
for (var index = 0, el, len = elements.length; index < len; index++) {
el = elements[index];
var klass = fabric[capitalize(el.tagName)];
if (klass && klass.fromElement) {
try {
@ -356,7 +357,7 @@
else {
checkIfDone();
}
});
}
};
/**

View file

@ -511,9 +511,7 @@
* @return {fabric.Path} Instance of fabric.Path
*/
fabric.Path.fromElement = function(element, options) {
var parsedAttributes = fabric.parseAttributes(element, fabric.Path.ATTRIBUTE_NAMES),
path = parsedAttributes.d;
delete parsedAttributes.d;
return new fabric.Path(path, extend(parsedAttributes, options));
var parsedAttributes = fabric.parseAttributes(element, fabric.Path.ATTRIBUTE_NAMES);
return new fabric.Path(parsedAttributes.d, extend(parsedAttributes, options));
};
})(this);

View file

@ -5,7 +5,7 @@
* @param {Object} destination Where to copy to
* @param {Object} source Where to copy from
*/
function extend(destination, source) {
function extend(destination, source) {
// JScript DontEnum bug is not taken care of
for (var property in source) {
destination[property] = source[property];

View file

@ -29,7 +29,7 @@
var logEl = document.getElementById('log');
(function testRaphael() {
/*(function testRaphael() {
var start = function () {
// storing original coordinates
@ -56,6 +56,7 @@
logEl.innerHTML = 'Raphael: <b>' + (new Date() - startTime) + '</b>ms<br>';
})();
*/
(function testFabric() {