Bug 1225923 - part 4 - fix AppendElement(nsDependentCString(...)) call in nsClipboardProxy.cpp; r=roc
authorNathan Froyd <froydnj@mozilla.com>
Wed, 18 Nov 2015 10:55:41 -0500
changeset 274903 3575f06c6dd18d7cd45826c5d91922aef1a367b4
parent 274902 6d26e408810ffb9775993017fe8f8da26ec552ef
child 274904 5e8e09fa2bbf5d0c8f22a3f8a79711ff17a67af5
push id68718
push usernfroyd@mozilla.com
push dateTue, 01 Dec 2015 14:08:13 +0000
treeherdermozilla-inbound@5e8e09fa2bbf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1225923
milestone45.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 1225923 - part 4 - fix AppendElement(nsDependentCString(...)) call in nsClipboardProxy.cpp; r=roc I think the intent of this call is not to copy the flavor data passed in, but to simply convert it to a friendlier nsCString container for serializing to an IPC message. Since we won't be retaining references to the passed-in strings after this function returns, we can make the elements of our temporary array actually dependent strings, rather than creating temporary dependent strings that would need to be copied into the array.
widget/nsClipboardProxy.cpp
--- a/widget/nsClipboardProxy.cpp
+++ b/widget/nsClipboardProxy.cpp
@@ -122,18 +122,19 @@ nsClipboardProxy::EmptyClipboard(int32_t
 NS_IMETHODIMP
 nsClipboardProxy::HasDataMatchingFlavors(const char **aFlavorList,
                                          uint32_t aLength, int32_t aWhichClipboard,
                                          bool *aHasType)
 {
   *aHasType = false;
 
   nsTArray<nsCString> types;
+  nsCString* t = types.AppendElements(aLength);
   for (uint32_t j = 0; j < aLength; ++j) {
-    types.AppendElement(nsDependentCString(aFlavorList[j]));
+    t[j].Rebind(aFlavorList[j], nsCharTraits<char>::length(aFlavorList[j]));
   }
 
   ContentChild::GetSingleton()->SendClipboardHasType(types, aWhichClipboard, aHasType);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP