Bug 1385324 - Part 1: Use a preallocated buffer of 100 elements to try to avoid memory allocations in HTMLFormControlsCollection::GetSortedControls(); r=qdot
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 28 Jul 2017 11:33:41 -0400
changeset 422964 485ceaeda92239b569b49989845fdee594c3c0a9
parent 422963 5a6100bac2393e0eb99b7e0f4feeb3b806fde7f7
child 422965 1ba4cfc4fa6289f4ba92886099c131ed85edd8fd
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1385324
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1385324 - Part 1: Use a preallocated buffer of 100 elements to try to avoid memory allocations in HTMLFormControlsCollection::GetSortedControls(); r=qdot
dom/html/HTMLFormElement.cpp
--- a/dom/html/HTMLFormElement.cpp
+++ b/dom/html/HTMLFormElement.cpp
@@ -1016,17 +1016,19 @@ HTMLFormElement::NotifySubmitObservers(n
 
   return rv;
 }
 
 
 nsresult
 HTMLFormElement::WalkFormElements(HTMLFormSubmission* aFormSubmission)
 {
-  nsTArray<nsGenericHTMLFormElement*> sortedControls;
+  // This shouldn't be called recursively, so use a rather large value
+  // for the preallocated buffer.
+  AutoTArray<nsGenericHTMLFormElement*, 100> sortedControls;
   nsresult rv = mControls->GetSortedControls(sortedControls);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t len = sortedControls.Length();
 
   // Hold a reference to the elements so they can't be deleted while
   // calling SubmitNamesValues().
   for (uint32_t i = 0; i < len; ++i) {
@@ -1863,17 +1865,19 @@ HTMLFormElement::ForgetCurrentSubmission
   mWebProgress = nullptr;
 }
 
 bool
 HTMLFormElement::CheckFormValidity(nsIMutableArray* aInvalidElements) const
 {
   bool ret = true;
 
-  nsTArray<nsGenericHTMLFormElement*> sortedControls;
+  // This shouldn't be called recursively, so use a rather large value
+  // for the preallocated buffer.
+  AutoTArray<nsGenericHTMLFormElement*, 100> sortedControls;
   if (NS_FAILED(mControls->GetSortedControls(sortedControls))) {
     return false;
   }
 
   uint32_t len = sortedControls.Length();
 
   // Hold a reference to the elements so they can't be deleted while calling
   // the invalid events.