From 17d100576923e00673b295b6bfacb0558eb0925b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Ko=C5=82odziejski?= Date: Fri, 29 Aug 2014 11:14:00 +0200 Subject: [PATCH] Bug 429732 - speed up highlighting by optimizing _getEditableNode. r=ehsan --- toolkit/modules/Finder.jsm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/toolkit/modules/Finder.jsm b/toolkit/modules/Finder.jsm index 10b4b0f775b..3abbf62fa2e 100644 --- a/toolkit/modules/Finder.jsm +++ b/toolkit/modules/Finder.jsm @@ -613,19 +613,18 @@ Finder.prototype = { }, /* - * For a given node, walk up it's parent chain, to try and find an - * editable node. + * For a given node returns its editable parent or null if there is none. + * It's enough to check if aNode is a text node and its parent's parent is + * instance of nsIDOMNSEditableElement. * * @param aNode the node we want to check * @returns the first node in the parent chain that is editable, * null if there is no such node */ _getEditableNode: function (aNode) { - while (aNode) { - if (aNode instanceof Ci.nsIDOMNSEditableElement) - return aNode.editor ? aNode : null; - - aNode = aNode.parentNode; + if (aNode.nodeType === aNode.TEXT_NODE && aNode.parentNode && aNode.parentNode.parentNode && + aNode.parentNode.parentNode instanceof Ci.nsIDOMNSEditableElement) { + return aNode.parentNode.parentNode; } return null; },