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
function importGroup(svg, type) {
var items = [],
nodes = svg.childNodes,
compound = type === 'clippath';
var nodes = svg.childNodes,
compound = type === 'clippath',
group = compound ? new CompoundPath() : new Group();
for (var i = 0, l = nodes.length; i < l; i++) {
var child = nodes[i];
if (child.nodeType == 1) {
var item = importSvg(child);
// If adding compound paths to other compound paths,
var child = nodes[i],
item;
if (child.nodeType == 1 && (item = importSvg(child))) {
// If adding CompoundPaths to other CompoundPaths,
// we need to "unbox" them first:
if (item) {
if (compound && item instanceof CompoundPath) {
items.push.apply(items, item.removeChildren());
item.remove();
} else {
items.push(item);
}
if (compound && item instanceof CompoundPath) {
group.addChildren(item.removeChildren());
item.remove();
} else {
group.addChild(item);
}
}
}
return new (compound ? CompoundPath : Group)(items);
return group;
}
function importPoly(svg, type) {