0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

More efficient forEachChildInRange fn.

No need for a tree walker, and we don't waste time iterating into children
that can never match the filter function.
This commit is contained in:
Neil Jenkins 2015-06-17 14:12:23 +07:00
parent 8b112b7615
commit d9872fb4b2
3 changed files with 15 additions and 19 deletions

View file

@ -3622,15 +3622,13 @@ proto.setTextDirection = function ( direction ) {
function forEachChildInRange ( rootNode, range, iterator ) {
var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT,
function ( node ) {
return node.parentNode === rootNode &&
isNodeContainedInRange( range, node, false /* include partials */ );
}
);
var node;
while ( node = walker.nextNode() ) {
iterator( node );
var childNodes = rootNode.childNodes,
node = rootNode.firstChild;
while ( node ) {
if ( isNodeContainedInRange( range, node, false ) ) {
iterator( node );
}
node = node.nextSibling;
}
}

File diff suppressed because one or more lines are too long

View file

@ -2164,15 +2164,13 @@ proto.setTextDirection = function ( direction ) {
function forEachChildInRange ( rootNode, range, iterator ) {
var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT,
function ( node ) {
return node.parentNode === rootNode &&
isNodeContainedInRange( range, node, false /* include partials */ );
}
);
var node;
while ( node = walker.nextNode() ) {
iterator( node );
var childNodes = rootNode.childNodes,
node = rootNode.firstChild;
while ( node ) {
if ( isNodeContainedInRange( range, node, false ) ) {
iterator( node );
}
node = node.nextSibling;
}
}