Remove aStartAfterNode from WalkDescendantsSetDirectionFromText. Bug 828054, r=ehsan, a=bajaj
authorSimon Montagu <smontagu@smontagu.org>
Sun, 13 Jan 2013 08:09:00 -0800
changeset 127351 96a7615ccad0ea3e5fca91f5c007f134a1c3ea60
parent 127350 1a6a636b116bdb75bbe76094c2f320272aebe4ec
child 127352 24b80b8f4da2d280294e8e9804f88b3fb798a157
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, bajaj
bugs828054
milestone20.0a2
Remove aStartAfterNode from WalkDescendantsSetDirectionFromText. Bug 828054, r=ehsan, a=bajaj
content/base/src/DirectionalityUtils.cpp
--- a/content/base/src/DirectionalityUtils.cpp
+++ b/content/base/src/DirectionalityUtils.cpp
@@ -347,65 +347,27 @@ GetDirectionFromText(const nsTextFragmen
   return GetDirectionFromText(aFrag->Get1b(), aFrag->GetLength(),
                                  aFirstStrong);
 }
 
 /**
  * Set the directionality of a node with dir=auto as defined in
  * http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#the-directionality
  *
- * @param[in] aStartAfterNode as an optimization, a caller may pass in a node
- *            from which to begin walking the descendants of aElement, if it is
- *            known that all text nodes before this node do not contain any
- *            strong directional characters
  * @return the text node containing the character that determined the direction
  */
 static nsINode*
-WalkDescendantsSetDirectionFromText(Element* aElement, bool aNotify = true,
-                                       nsINode* aStartAfterNode = nullptr)
+WalkDescendantsSetDirectionFromText(Element* aElement, bool aNotify = true)
 {
   MOZ_ASSERT(aElement, "aElement is null");
   if (DoesNotParticipateInAutoDirection(aElement)) {
     return nullptr;
   }
 
-  nsIContent* child;
-  if (aStartAfterNode &&
-      nsContentUtils::ContentIsDescendantOf(aStartAfterNode, aElement)) {
-    nsIContent* firstNode = aStartAfterNode->GetNextNode(aElement);
-
-#ifdef DEBUG
-    // In debug builds, assert that aStartAfterNode is correctly set by checking
-    // that text node descendants of elements up to aStartAfterNode don't have
-    // any strong directional characters
-    child = aElement->GetFirstChild();
-    while (child && child != firstNode) {
-      // Skip over nodes whose text node descendants don't affect directionality
-      // of their ancestors
-      if (child->IsElement() &&
-          (DoesNotParticipateInAutoDirection(child->AsElement()) ||
-           child->NodeInfo()->Equals(nsGkAtoms::bdi) ||
-           child->HasFixedDir())) {
-        child = child->GetNextNonChildNode(aElement);
-        continue;
-      }
-
-      if (child->NodeType() == nsIDOMNode::TEXT_NODE) {
-        MOZ_ASSERT(GetDirectionFromText(child->GetText()) == eDir_NotSet,
-                   "Strong directional characters before aStartAfterNode");
-      }
-      child = child->GetNextNode(aElement);
-    }
-#else
-    child = firstNode;
-#endif
-  } else {
-    child = aElement->GetFirstChild();
-  }
-
+  nsIContent* child = aElement->GetFirstChild();
   while (child) {
     if (child->IsElement() &&
         (DoesNotParticipateInAutoDirection(child->AsElement()) ||
          child->NodeInfo()->Equals(nsGkAtoms::bdi) ||
          child->HasFixedDir())) {
       child = child->GetNextNonChildNode(aElement);
       continue;
     }
@@ -501,38 +463,36 @@ private:
     return PL_DHASH_NEXT;
   }
 
   static PLDHashOperator ResetNodeDirection(nsPtrHashKey<Element>* aEntry, void* aData)
   {
     MOZ_ASSERT(aEntry->GetKey()->IsElement(), "Must be an Element");
     // run the downward propagation algorithm
     // and remove the text node from the map
-    nsINode* startAfterNode = static_cast<Element*>(aData);
     Element* rootNode = aEntry->GetKey();
-    nsINode* textNode = WalkDescendantsSetDirectionFromText(rootNode, true,
-                                                            startAfterNode);
+    nsINode* textNode = WalkDescendantsSetDirectionFromText(rootNode, true);
     if (textNode) {
       nsTextNodeDirectionalityMap::AddEntryToMap(textNode, rootNode);
     } else {
       rootNode->ClearHasDirAutoSet();
       rootNode->UnsetProperty(nsGkAtoms::dirAutoSetBy);
     }
     return PL_DHASH_REMOVE;
   }
 
 public:
   void UpdateAutoDirection(Directionality aDir)
   {
     mElements.EnumerateEntries(SetNodeDirection, &aDir);
   }
 
-  void ResetAutoDirection(nsINode* aTextNode, nsINode* aStartAfterNode)
+  void ResetAutoDirection()
   {
-    mElements.EnumerateEntries(ResetNodeDirection, aStartAfterNode);
+    mElements.EnumerateEntries(ResetNodeDirection, nullptr);
   }
 
   static void RemoveElementFromMap(nsINode* aTextNode, Element* aElement)
   {
     if (aTextNode->HasTextNodeDirectionalityMap()) {
       GetDirectionalityMap(aTextNode)->RemoveEntry(aTextNode, aElement);
     }
   }
@@ -549,23 +509,21 @@ public:
 
   static void UpdateTextNodeDirection(nsINode* aTextNode, Directionality aDir)
   {
     MOZ_ASSERT(aTextNode->HasTextNodeDirectionalityMap(),
                "Map missing in UpdateTextNodeDirection");
     GetDirectionalityMap(aTextNode)->UpdateAutoDirection(aDir);
   }
 
-  static void ResetTextNodeDirection(nsINode* aTextNode,
-                                     nsINode* aStartAfterNode = nullptr)
+  static void ResetTextNodeDirection(nsINode* aTextNode)
   {
     MOZ_ASSERT(aTextNode->HasTextNodeDirectionalityMap(),
                "Map missing in ResetTextNodeDirection");
-    GetDirectionalityMap(aTextNode)->ResetAutoDirection(aTextNode,
-                                                        aStartAfterNode);
+    GetDirectionalityMap(aTextNode)->ResetAutoDirection();
   }
 };
 
 Directionality
 RecomputeDirectionality(Element* aElement, bool aNotify)
 {
   MOZ_ASSERT(!aElement->HasDirAuto(),
              "RecomputeDirectionality called with dir=auto");
@@ -659,17 +617,17 @@ WalkDescendantsResetAutoDirection(Elemen
   nsIContent* child = aElement->GetFirstChild();
   while (child) {
     if (child->HasDirAuto()) {
       child = child->GetNextNonChildNode(aElement);
       continue;
     }
 
     if (child->HasTextNodeDirectionalityMap()) {
-      nsTextNodeDirectionalityMap::ResetTextNodeDirection(child, child);
+      nsTextNodeDirectionalityMap::ResetTextNodeDirection(child);
     }
     child = child->GetNextNode(aElement);
   }
 }
 
 void
 WalkDescendantsSetDirAuto(Element* aElement, bool aNotify)
 {