-
Notifications
You must be signed in to change notification settings - Fork 537
Closed
Description
I found the the Flatten function is extremely slow when dealing with 40k+ text nodes. The issue is that it is using the javascript "concat" function, which is extremely slow. This function works 1000x faster and returns the same result:
return jq.map(function() {
function isArray(obj) {
return toString.call(obj) === '[object Array]';
};
function flatten(branch, flat, max, depth) {
flat = flat || [ ]; max = max || 1;
depth = ( depth ? depth + 1 : 1);
for(var i in branch) {
if(isArray(branch[i])) {
if((max < 0) || (depth <= max)) {
flatten(branch[i], flat, max, depth);
} else { flat.push(branch[i]); }
} else { flat.push(branch[i]); }
}
return flat;
};
return flatten(getTextNodes(this), [], -1, -1);
})
Metadata
Metadata
Assignees
Labels
No labels