Bug 1272397 - use AppendElements in GetColorsForProperty; r=tromey
authorNathan Froyd <froydnj@gmail.com>
Thu, 19 May 2016 21:48:59 -0400
changeset 298164 39496abed3def6af2c5342a84263d3a03c457db7
parent 298163 3d201ae294f8adb86423b2506c6d38854498a097
child 298165 ca34a07172f67508bd75964c0b617e8a344d8397
push id77050
push usernfroyd@mozilla.com
push dateThu, 19 May 2016 17:50:15 +0000
treeherdermozilla-inbound@39496abed3de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1272397
milestone49.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 1272397 - use AppendElements in GetColorsForProperty; r=tromey Creating an array of exactly the size that we need is faster than possibly going through several rounds of reallocation and copying.
layout/inspector/inDOMUtils.cpp
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -605,18 +605,19 @@ static void GetColorsForProperty(const u
                                  nsTArray<nsString>& aArray)
 {
   if (aParserVariant & VARIANT_COLOR) {
     // GetKeywordsForProperty and GetOtherValuesForProperty assume aArray is sorted,
     // and if aArray is not empty here, then it's not going to be sorted coming out.
     MOZ_ASSERT(aArray.Length() == 0);
     size_t size;
     const char * const *allColorNames = NS_AllColorNames(&size);
+    nsString* utf16Names = aArray.AppendElements(size);
     for (size_t i = 0; i < size; i++) {
-      CopyASCIItoUTF16(allColorNames[i], *aArray.AppendElement());
+      CopyASCIItoUTF16(allColorNames[i], utf16Names[i]);
     }
     InsertNoDuplicates(aArray, NS_LITERAL_STRING("currentColor"));
   }
   return;
 }
 
 static void GetOtherValuesForProperty(const uint32_t aParserVariant,
                                       nsTArray<nsString>& aArray)