Improve importGroup() code a bit by directly filling an Item instead of an array first.

This commit is contained in:
Jürg Lehni 2012-11-06 20:28:20 -08:00
parent 1cb6a7fc3c
commit b1c24e2762

View file

@ -43,27 +43,25 @@ new function() {
// Define importer functions for various SVG node types // Define importer functions for various SVG node types
function importGroup(svg, type) { function importGroup(svg, type) {
var items = [], var nodes = svg.childNodes,
nodes = svg.childNodes, compound = type === 'clippath',
compound = type === 'clippath'; group = compound ? new CompoundPath() : new Group();
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var child = nodes[i]; var child = nodes[i],
if (child.nodeType == 1) { item;
var item = importSvg(child); if (child.nodeType == 1 && (item = importSvg(child))) {
// If adding compound paths to other compound paths, // If adding CompoundPaths to other CompoundPaths,
// we need to "unbox" them first: // we need to "unbox" them first:
if (item) { if (compound && item instanceof CompoundPath) {
if (compound && item instanceof CompoundPath) { group.addChildren(item.removeChildren());
items.push.apply(items, item.removeChildren()); item.remove();
item.remove(); } else {
} else { group.addChild(item);
items.push(item);
}
} }
} }
} }
return new (compound ? CompoundPath : Group)(items); return group;
} }
function importPoly(svg, type) { function importPoly(svg, type) {