Bug 1184238 - Use emplaceBack instead of growByUninitialized(1) and placement-new in js::SavedStacks; r=shu
authorNick Fitzgerald <fitzgen@gmail.com>
Mon, 20 Jul 2015 11:13:28 -0700
changeset 253718 5eb67d10b3c06238b65d06ce86ca083a03c2b668
parent 253717 bb14867fc943f7fcbb16e89284753ab24da4fd38
child 253719 0fe1861b2c08009fa56e36d195d38a850280bad2
push id62533
push usernfitzgerald@mozilla.com
push dateMon, 20 Jul 2015 18:13:58 +0000
treeherdermozilla-inbound@0fe1861b2c08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1184238
milestone42.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 1184238 - Use emplaceBack instead of growByUninitialized(1) and placement-new in js::SavedStacks; r=shu
js/src/vm/SavedStacks.cpp
--- a/js/src/vm/SavedStacks.cpp
+++ b/js/src/vm/SavedStacks.cpp
@@ -925,38 +925,34 @@ SavedStacks::insertFrames(JSContext* cx,
             }
         } else if (asyncActivation != &activation) {
             // We found an async stack in the previous activation, and we
             // walked past the oldest frame of that activation, we're done.
             break;
         }
 
         AutoLocationValueRooter location(cx);
-
         {
             AutoCompartment ac(cx, iter.compartment());
             if (!cx->compartment()->savedStacks().getLocation(cx, iter, &location))
                 return false;
         }
 
-        // Use growByUninitialized and placement-new instead of just append.
-        // We'd ideally like to use an emplace method once Vector supports it.
-        if (!stackChain->growByUninitialized(1)) {
+        auto displayAtom = iter.isNonEvalFunctionFrame() ? iter.functionDisplayAtom() : nullptr;
+        if (!stackChain->emplaceBack(location->source,
+                                     location->line,
+                                     location->column,
+                                     displayAtom,
+                                     nullptr,
+                                     nullptr,
+                                     iter.compartment()->principals()))
+        {
             ReportOutOfMemory(cx);
             return false;
         }
-        new (&stackChain->back()) SavedFrame::Lookup(
-          location->source,
-          location->line,
-          location->column,
-          iter.isNonEvalFunctionFrame() ? iter.functionDisplayAtom() : nullptr,
-          nullptr,
-          nullptr,
-          iter.compartment()->principals()
-        );
 
         ++iter;
 
         // If maxFrameCount is zero there's no limit on the number of frames.
         if (maxFrameCount == 0)
             continue;
 
         if (maxFrameCount == 1) {
@@ -1006,23 +1002,20 @@ SavedStacks::adoptAsyncStack(JSContext* 
     // still don't enforce an upper limit if the caller requested more frames.
     if (maxFrameCount == 0)
         maxFrameCount = ASYNC_STACK_MAX_FRAME_COUNT;
 
     // Accumulate the vector of Lookup objects in |stackChain|.
     SavedFrame::AutoLookupVector stackChain(cx);
     SavedFrame* currentSavedFrame = asyncStack;
     for (unsigned i = 0; i < maxFrameCount && currentSavedFrame; i++) {
-        // Use growByUninitialized and placement-new instead of just append.
-        // We'd ideally like to use an emplace method once Vector supports it.
-        if (!stackChain->growByUninitialized(1)) {
+        if (!stackChain->emplaceBack(*currentSavedFrame)) {
             ReportOutOfMemory(cx);
             return false;
         }
-        new (&stackChain->back()) SavedFrame::Lookup(*currentSavedFrame);
 
         // Attach the asyncCause to the youngest frame.
         if (i == 0)
             stackChain->back().asyncCause = asyncCauseAtom;
 
         currentSavedFrame = currentSavedFrame->getParent();
     }