<https://webkit.org/b/119536> Refactor highestEditableRoot to avoid a redundant call...
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Aug 2013 01:31:34 +0000 (01:31 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Aug 2013 01:31:34 +0000 (01:31 +0000)
Reviewed by Benjamin Poulain.

Refactor highestEditableRoot to avoid an extra tree walk. We now walk up the ancestor chain up to
the first root editable element exactly once.

* dom/Node.cpp:
(WebCore::Node::rendererIsEditable): Change the order of conditions to make the evaluation faster
when we don't have to check RenderStyle's value.
* editing/htmlediting.cpp:
(WebCore::highestEditableRoot):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154212 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Node.cpp
Source/WebCore/editing/htmlediting.cpp

index db41f14bcfa7b7d2b6e34f3c5bca3b4248881fd9..45dac44450ad432d619fdd81821140c3a7fbbbf4 100644 (file)
@@ -1,3 +1,18 @@
+2013-08-16  Ryosuke Niwa  <rniwa@webkit.org>
+
+        <https://webkit.org/b/119536> Refactor highestEditableRoot to avoid a redundant call to rendererIsEditable
+
+        Reviewed by Benjamin Poulain.
+
+        Refactor highestEditableRoot to avoid an extra tree walk. We now walk up the ancestor chain up to
+        the first root editable element exactly once.
+
+        * dom/Node.cpp:
+        (WebCore::Node::rendererIsEditable): Change the order of conditions to make the evaluation faster
+        when we don't have to check RenderStyle's value.
+        * editing/htmlediting.cpp:
+        (WebCore::highestEditableRoot):
+
 2013-08-16  Benjamin Poulain  <benjamin@webkit.org>
 
         Remove a useless #include of SelectorChecker.h
index 5e36c43bf8d234b0d41eee56ceec6ea4f89cfd3c..309b612ec54e7d88cab91f3d44d415c658f608cd 100644 (file)
@@ -629,7 +629,7 @@ bool Node::rendererIsEditable(EditableLevel editableLevel, UserSelectAllTreatmen
 #if ENABLE(USERSELECT_ALL)
             // Elements with user-select: all style are considered atomic
             // therefore non editable.
-            if (node->renderer()->style()->userSelect() == SELECT_ALL && treatment == UserSelectAllIsAlwaysNonEditable)
+            if (treatment == UserSelectAllIsAlwaysNonEditable && node->renderer()->style()->userSelect() == SELECT_ALL)
                 return false;
 #else
             UNUSED_PARAM(treatment);
index f3c70e06d3b192ffad9a70eb85aa878a9418b775..c725a477cefb65edbb878853afae0d516f48232d 100644 (file)
@@ -112,21 +112,21 @@ Node* highestEditableRoot(const Position& position, EditableType editableType)
     Node* node = position.deprecatedNode();
     if (!node)
         return 0;
-        
-    Node* highestRoot = editableRootForPosition(position, editableType);
-    if (!highestRoot)
+
+    Node* highestEditableRoot = editableRootForPosition(position, editableType);
+    if (!highestEditableRoot)
         return 0;
-    
-    node = highestRoot;
-    while (node) {
-        if (node->rendererIsEditable(editableType))
-            highestRoot = node;
-        if (node->hasTagName(bodyTag))
-            break;
+
+    node = highestEditableRoot;
+    while (!node->hasTagName(bodyTag)) {
         node = node->parentNode();
+        if (!node)
+            break;
+        if (node->rendererIsEditable(editableType))
+            highestEditableRoot = node;
     }
-    
-    return highestRoot;
+
+    return highestEditableRoot;
 }
 
 Node* lowestEditableAncestor(Node* node)