Optimize appends in CFX_XMLNode::InsertChildNode().

Skip to the end of the linked list instead of traversing it.

BUG=chromium:895234

Change-Id: I56d6bee3cd099a1a7343eb2b067d522ec69c261a
Reviewed-on: https://pdfium-review.googlesource.com/c/44172
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp
index 59eb3f7..4fbc8bc 100644
--- a/core/fxcrt/xml/cfx_xmlnode.cpp
+++ b/core/fxcrt/xml/cfx_xmlnode.cpp
@@ -58,12 +58,18 @@
     return;
   }
 
-  int32_t iCount = 0;
-  CFX_XMLNode* pFind = first_child_;
+  CFX_XMLNode* pFind;
   // Note, negative indexes, and indexes after the end of the list will result
   // in appending to the list.
-  while (++iCount != index && pFind->next_sibling_)
-    pFind = pFind->next_sibling_;
+  if (index < 0) {
+    // Optimize the negative index case.
+    pFind = last_child_;
+  } else {
+    pFind = first_child_;
+    int32_t iCount = 0;
+    while (++iCount != index && pFind->next_sibling_)
+      pFind = pFind->next_sibling_;
+  }
 
   pNode->prev_sibling_ = pFind;
   if (pFind->next_sibling_)