Bug 518950 - FindNextTextNode in mozInlineSpellWordUtil.cpp is slow, r=bz

This commit is contained in:
Olli Pettay 2009-09-30 13:45:14 +03:00
Родитель 0cf3cebd9d
Коммит 8879185a87
1 изменённых файлов: 19 добавлений и 21 удалений

Просмотреть файл

@ -50,6 +50,7 @@
#include "nsIDOMHTMLBRElement.h"
#include "nsUnicharUtilCIID.h"
#include "nsServiceManagerUtils.h"
#include "nsIContent.h"
// IsIgnorableCharacter
//
@ -177,39 +178,36 @@ FindNextTextNode(nsIDOMNode* aNode, PRInt32 aOffset, nsIDOMNode* aRoot)
NS_PRECONDITION(aNode, "Null starting node?");
NS_ASSERTION(!IsTextNode(aNode), "FindNextTextNode should start with a non-text node");
nsIDOMNode* checkNode;
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMNode> checkNode;
// Need to start at the aOffset'th child
nsCOMPtr<nsIDOMNode> child;
aNode->GetFirstChild(getter_AddRefs(child));
while (child && aOffset > 0) {
nsCOMPtr<nsIDOMNode> next;
child->GetNextSibling(getter_AddRefs(next));
child.swap(next);
--aOffset;
}
nsIContent* child = node->GetChildAt(aOffset);
if (child) {
checkNode = child;
checkNode = do_QueryInterface(child);
} else {
// aOffset was beyond the end of the child list.
// goto next node in a preorder DOM traversal.
nsCOMPtr<nsIDOMNode> next;
aNode->GetNextSibling(getter_AddRefs(next));
while (!next) {
// Go up
aNode->GetParentNode(getter_AddRefs(next));
if (next == aRoot || !next) {
return nsnull;
nsINode* next = node->GetSibling(1);
if (!next) {
nsCOMPtr<nsINode> root = do_QueryInterface(aRoot);
while (!next) {
// Go up
next = node->GetNodeParent();
if (next == root || !next) {
return nsnull;
}
node = next;
next = node->GetSibling(1);
}
aNode = next;
aNode->GetNextSibling(getter_AddRefs(next));
}
checkNode = next;
checkNode = do_QueryInterface(next);
}
while (checkNode && !IsTextNode(checkNode)) {
checkNode = FindNextNode(checkNode, aRoot);
}
return checkNode;
return checkNode.get();
}
// mozInlineSpellWordUtil::SetEnd