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 275021 3575f06c6dd18d7cd45826c5d91922aef1a367b4
parent 275020 6d26e408810ffb9775993017fe8f8da26ec552ef
child 275022 5e8e09fa2bbf5d0c8f22a3f8a79711ff17a67af5
push id16492
push userkwierso@gmail.com
push dateWed, 02 Dec 2015 00:11:56 +0000
treeherderfx-team@efc976f76ff0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1225923
milestone45.0a1
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