Bug 1453129 - don't needlessly copy data in nsClipboardProxy; r=smaug
authorNathan Froyd <froydnj@mozilla.com>
Tue, 10 Apr 2018 19:07:40 -0400
changeset 412778 67758cf8ae6ff6413f1d24923f5db8b2d5fb369c
parent 412777 8c6cf2dab2ae40186b897b75f87ec0d5a9118626
child 412779 6393fa23c234090d931cbaa1d8cab65edbd88a37
push id33818
push userapavel@mozilla.com
push dateWed, 11 Apr 2018 14:36:40 +0000
treeherdermozilla-central@cfe6399e142c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1453129
milestone61.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 1453129 - don't needlessly copy data in nsClipboardProxy; r=smaug We're already going to copy the data when we initialize the nsISupportsString here. There's no need to copy the data into a temporary object before passing it in to the nsISupportsString. And as long as we're fixing the big mistakes, we might as well fix the small ones, like copying the flavor string from the IPC object.
widget/nsClipboardProxy.cpp
--- a/widget/nsClipboardProxy.cpp
+++ b/widget/nsClipboardProxy.cpp
@@ -76,26 +76,26 @@ nsClipboardProxy::GetData(nsITransferabl
   for (uint32_t j = 0; j < items.Length(); ++j) {
     const IPCDataTransferItem& item = items[j];
 
     if (item.data().type() == IPCDataTransferData::TnsString) {
       nsCOMPtr<nsISupportsString> dataWrapper =
         do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
 
-      nsString data = item.data().get_nsString();
+      const nsString& data = item.data().get_nsString();
       rv = dataWrapper->SetData(data);
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = aTransferable->SetTransferData(item.flavor().get(), dataWrapper,
                                           data.Length() * sizeof(char16_t));
       NS_ENSURE_SUCCESS(rv, rv);
     } else if (item.data().type() == IPCDataTransferData::TShmem) {
       // If this is an image, convert it into an nsIInputStream.
-      nsCString flavor = item.flavor();
+      const nsCString& flavor = item.flavor();
       mozilla::ipc::Shmem data = item.data().get_Shmem();
       if (flavor.EqualsLiteral(kJPEGImageMime) ||
           flavor.EqualsLiteral(kJPGImageMime) ||
           flavor.EqualsLiteral(kPNGImageMime) ||
           flavor.EqualsLiteral(kGIFImageMime)) {
         nsCOMPtr<nsIInputStream> stream;
 
         NS_NewCStringInputStream(getter_AddRefs(stream),