Bug 1489944 - Fixed some std::move warnings - r=froydnj
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 10 Sep 2018 15:51:48 +0000
changeset 435614 51022564014403f18812deeaeac0bab3921f0f6d
parent 435613 9dc78b12d194ffc0ec9fe9e08626b51dfe02afa0
child 435615 7b0d4ede690af8e8e04dd0c498c2a02c636b1156
push id107698
push usercsabou@mozilla.com
push dateTue, 11 Sep 2018 10:17:55 +0000
treeherdermozilla-inbound@77ef88dd1272 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1489944
milestone64.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 1489944 - Fixed some std::move warnings - r=froydnj > dom/media/gmp/CDMStorageIdProvider.cpp(63,10): warning: > local variable 'storageId' will be copied despite being returned by name [-Wreturn-std-move] nsAutoCString -> nsCString, will add std::move(). > layout/painting/DisplayItemClip.cpp(581,10): warning: > local variable 'str' will be copied despite being returned by name [-Wreturn-std-move] nsAutoCString -> nsCString, will add std::move(). > layout/painting/DisplayItemClipChain.cpp(88,10): warning: > local variable 'str' will be copied despite being returned by name [-Wreturn-std-move] nsAutoCString -> nsCString, will add std::move(). > layout/painting/nsDisplayList.cpp(179,10): warning: > local variable 'str' will be copied despite being returned by name [-Wreturn-std-move] nsAutoCString -> nsCString, will add std::move(). > gfx/thebes/gfxWindowsPlatform.cpp(454,10): warning: > moving a local object in a return statement prevents copy elision [-Wpessimizing-move] Will remove std::move(). > gfx/thebes/gfxFontEntry.cpp(245,20): warning: > local variable 'name' will be copied despite being returned by name [-Wreturn-std-move] nsAutoCString -> nsCString, will add std::move(). > netwerk/cookie/nsCookieService.cpp(4460,10): warning: > local variable 'path' will be copied despite being returned by name [-Wreturn-std-move] GetPathFromURI() result is stored in an nsAutoCString, so it might as well return that type. > toolkit/components/extensions/WebExtensionPolicy.cpp(462,12): warning: > local variable 'result' will be copied despite being returned by name [-Wreturn-std-move] > toolkit/components/extensions/WebExtensionPolicy.cpp(475,10): warning: > local variable 'result' will be copied despite being returned by name [-Wreturn-std-move] `result` may be empty or may be arbitrarily long, so I'll use nsCString inside the function. > toolkit/xre/CmdLineAndEnvUtils.h(349,10): warning: > moving a local object in a return statement prevents copy elision [-Wpessimizing-move] Returning an UniquePtr, will remove std::move(). Also will `return s` instead of `return nullptr` when `(!s)`, to avoid extra construction which could also prevent elision (not entirely sure, but it's at least not worse!); and it's clearer that the two `return`s return the same already-constructed on-stack object. > tools/profiler/core/shared-libraries-win32.cc(111,10): warning: > local variable 'version' will be copied despite being returned by name [-Wreturn-std-move] nsPrintfCString -> nsCString, will add std::move(). > xpcom/glue/FileUtils.cpp(179,10): warning: > local variable 'fullName' will be copied despite being returned by name [-Wreturn-std-move] > xpcom/glue/FileUtils.cpp(209,10): warning: > local variable 'path' will be copied despite being returned by name [-Wreturn-std-move] nsAuto{,C}String -> ns{,C}String, will add std::move(). This allowed removals of 'AllowCompilerWarnings' from layout/painting, netwerk/cookie, and toolkit/components/extensions. Differential Revision: https://phabricator.services.mozilla.com/D5425
dom/media/gmp/CDMStorageIdProvider.cpp
gfx/thebes/gfxFontEntry.cpp
gfx/thebes/gfxWindowsPlatform.cpp
layout/painting/DisplayItemClip.cpp
layout/painting/DisplayItemClipChain.cpp
layout/painting/moz.build
layout/painting/nsDisplayList.cpp
netwerk/cookie/moz.build
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
toolkit/components/extensions/WebExtensionPolicy.cpp
toolkit/components/extensions/moz.build
toolkit/xre/CmdLineAndEnvUtils.h
tools/profiler/core/shared-libraries-win32.cc
xpcom/glue/FileUtils.cpp
--- a/dom/media/gmp/CDMStorageIdProvider.cpp
+++ b/dom/media/gmp/CDMStorageIdProvider.cpp
@@ -55,13 +55,13 @@ CDMStorageIdProvider::ComputeStorageId(c
   }
 
   rv = hasher->Finish(false, storageId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     GMP_LOG("CDMStorageIdProvider::ComputeStorageId: failed to get the final hash result(0x%08" PRIx32 ")",
             static_cast<uint32_t>(rv));
     return EmptyCString();
   }
-  return storageId;
+  return std::move(storageId);
 #endif
 }
 
 } // namespace mozilla
\ No newline at end of file
--- a/gfx/thebes/gfxFontEntry.cpp
+++ b/gfx/thebes/gfxFontEntry.cpp
@@ -237,17 +237,17 @@ nsresult gfxFontEntry::ReadCMAP(FontInfo
 nsString
 gfxFontEntry::RealFaceName()
 {
     AutoTable nameTable(this, TRUETYPE_TAG('n','a','m','e'));
     if (nameTable) {
         nsAutoString name;
         nsresult rv = gfxFontUtils::GetFullNameFromTable(nameTable, name);
         if (NS_SUCCEEDED(rv)) {
-            return name;
+            return std::move(name);
         }
     }
     return Name();
 }
 
 gfxFont*
 gfxFontEntry::FindOrMakeFont(const gfxFontStyle *aStyle,
                              gfxCharacterMap* aUnicodeRangeMap)
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -446,17 +446,17 @@ gfxWindowsPlatform::GetBackendPrefs() co
     data.mCanvasBitmask |= BackendTypeBit(BackendType::DIRECT2D1_1);
     data.mCanvasDefault = BackendType::DIRECT2D1_1;
     // We do not use d2d for content when WebRender is used.
     if (!gfxVars::UseWebRender()) {
       data.mContentBitmask |= BackendTypeBit(BackendType::DIRECT2D1_1);
       data.mContentDefault = BackendType::DIRECT2D1_1;
     }
   }
-  return std::move(data);
+  return data;
 }
 
 void
 gfxWindowsPlatform::UpdateBackendPrefs()
 {
   BackendPrefsData data = GetBackendPrefs();
   // Remove DIRECT2D1 preference if D2D1Device does not exist.
   if (!Factory::HasD2D1Device()) {
--- a/layout/painting/DisplayItemClip.cpp
+++ b/layout/painting/DisplayItemClip.cpp
@@ -573,17 +573,17 @@ DisplayItemClip::ToString() const
                        r.mRadii[2],
                        r.mRadii[3],
                        r.mRadii[4],
                        r.mRadii[5],
                        r.mRadii[6],
                        r.mRadii[7]);
     }
   }
-  return str;
+  return std::move(str);
 }
 
 void
 DisplayItemClip::ToComplexClipRegions(
   int32_t aAppUnitsPerDevPixel,
   const layers::StackingContextHelper& aSc,
   nsTArray<wr::ComplexClipRegion>& aOutArray) const
 {
--- a/layout/painting/DisplayItemClipChain.cpp
+++ b/layout/painting/DisplayItemClipChain.cpp
@@ -80,17 +80,17 @@ DisplayItemClipChain::ToString(const Dis
                        sc->mASR->mScrollableFrame);
     } else {
       str.AppendPrintf("0x%p <%s> [root asr]", sc, sc->mClip.ToString().get());
     }
     if (sc->mParent) {
       str.AppendLiteral(", ");
     }
   }
-  return str;
+  return std::move(str);
 }
 
 bool
 DisplayItemClipChain::HasRoundedCorners() const
 {
   return mClip.GetRoundedRectCount() > 0 ||
          (mParent && mParent->HasRoundedCorners());
 }
--- a/layout/painting/moz.build
+++ b/layout/painting/moz.build
@@ -70,11 +70,8 @@ CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
 
 if CONFIG['CC_TYPE'] in ('msvc', 'clang-cl'):
     # This is intended as a temporary hack to support building with VS2015.
     # 'type cast': conversion from 'unsigned int' to 'void *' of greater size
     CXXFLAGS += ['-wd4312']
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
-
-if CONFIG['CC_TYPE'] == 'clang-cl':
-    AllowCompilerWarnings()  # workaround for bug 1090497
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -171,17 +171,17 @@ ActiveScrolledRoot::ToString(const Activ
 {
   nsAutoCString str;
   for (auto* asr = aActiveScrolledRoot; asr; asr = asr->mParent) {
     str.AppendPrintf("<0x%p>", asr->mScrollableFrame);
     if (asr->mParent) {
       str.AppendLiteral(", ");
     }
   }
-  return str;
+  return std::move(str);
 }
 
 static inline CSSAngle
 MakeCSSAngle(const nsCSSValue& aValue)
 {
   return CSSAngle(aValue.GetAngleValue(), aValue.GetUnit());
 }
 
--- a/netwerk/cookie/moz.build
+++ b/netwerk/cookie/moz.build
@@ -50,11 +50,8 @@ IPDL_SOURCES = [
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
-
-if CONFIG['CC_TYPE'] == 'clang-cl':
-    AllowCompilerWarnings()  # workaround for bug 1090497
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -4434,17 +4434,17 @@ nsCookieService::CheckDomain(nsCookieAtt
     return false;
   }
 
   // no domain specified, use hostFromURI
   aCookieAttributes.host = hostFromURI;
   return true;
 }
 
-nsCString
+nsAutoCString
 nsCookieService::GetPathFromURI(nsIURI* aHostURI)
 {
   // strip down everything after the last slash to get the path,
   // ignoring slashes in the query string part.
   // if we can QI to nsIURL, that'll take care of the query string portion.
   // otherwise, it's not an nsIURL and can't have a query string, so just find the last slash.
   nsAutoCString path;
   nsCOMPtr<nsIURL> hostURL = do_QueryInterface(aHostURI);
--- a/netwerk/cookie/nsCookieService.h
+++ b/netwerk/cookie/nsCookieService.h
@@ -258,17 +258,17 @@ class nsCookieService final : public nsI
 
   /**
    * Start watching the observer service for messages indicating that an app has
    * been uninstalled.  When an app is uninstalled, we get the cookie service
    * (thus instantiating it, if necessary) and clear all the cookies for that
    * app.
    */
   static void AppClearDataObserverInit();
-  static nsCString GetPathFromURI(nsIURI *aHostURI);
+  static nsAutoCString GetPathFromURI(nsIURI *aHostURI);
   static nsresult GetBaseDomain(nsIEffectiveTLDService *aTLDService, nsIURI *aHostURI, nsCString &aBaseDomain, bool &aRequireHostMatch);
   static nsresult GetBaseDomainFromHost(nsIEffectiveTLDService *aTLDService, const nsACString &aHost, nsCString &aBaseDomain);
   static bool DomainMatches(nsCookie* aCookie, const nsACString& aHost);
   static bool IsSameSiteEnabled();
   static bool PathMatches(nsCookie* aCookie, const nsACString& aPath);
   static bool CanSetCookie(nsIURI *aHostURI, const nsCookieKey& aKey, nsCookieAttributes &aCookieAttributes, bool aRequireHostMatch, CookieStatus aStatus, nsDependentCString &aCookieHeader, int64_t aServerTime, bool aFromHttp, nsIChannel* aChannel, bool aLeaveSercureAlone, bool &aSetCookie, mozIThirdPartyUtil* aThirdPartyUtil);
   static CookieStatus CheckPrefs(nsICookiePermission *aPermissionServices, uint8_t aCookieBehavior, bool aThirdPartySession, bool aThirdPartyNonsecureSession, nsIURI *aHostURI, bool aIsForeign, bool aIsTrackingResource, bool aIsFirstPartyStorageAccessGranted, const char *aCookieHeader, const int aNumOfCookies, const OriginAttributes& aOriginAttrs, uint32_t* aRejectedReason);
   static int64_t ParseServerTime(const nsCString &aServerTime);
--- a/toolkit/components/extensions/WebExtensionPolicy.cpp
+++ b/toolkit/components/extensions/WebExtensionPolicy.cpp
@@ -450,17 +450,17 @@ WebExtensionPolicy::IsRestrictedURI(cons
   }
 
   return false;
 }
 
 nsCString
 WebExtensionPolicy::BackgroundPageHTML() const
 {
-  nsAutoCString result;
+  nsCString result;
 
   if (mBackgroundScripts.IsNull()) {
     result.SetIsVoid(true);
     return result;
   }
 
   result.AppendLiteral(kBackgroundPageHTMLStart);
 
--- a/toolkit/components/extensions/moz.build
+++ b/toolkit/components/extensions/moz.build
@@ -95,11 +95,8 @@ XPCSHELL_TESTS_MANIFESTS += [
 ]
 
 SPHINX_TREES['webextensions'] = 'docs'
 
 with Files('docs/**'):
     SCHEDULES.exclusive = ['docs']
 
 include('/ipc/chromium/chromium-config.mozbuild')
-
-if CONFIG['CC_TYPE'] == 'clang-cl':
-    AllowCompilerWarnings()  # workaround for bug 1090497
--- a/toolkit/xre/CmdLineAndEnvUtils.h
+++ b/toolkit/xre/CmdLineAndEnvUtils.h
@@ -327,31 +327,31 @@ MakeCommandLine(int argc, wchar_t **argv
 
   // Protect against callers that pass 0 arguments
   if (len == 0) {
     len = 1;
   }
 
   auto s = MakeUnique<wchar_t[]>(len);
   if (!s) {
-    return nullptr;
+    return s;
   }
 
   wchar_t *c = s.get();
   for (i = 0; i < argc; ++i) {
     c = internal::ArgToString(c, argv[i]);
     if (i + 1 != argc) {
       *c = ' ';
       ++c;
     }
   }
 
   *c = '\0';
 
-  return std::move(s);
+  return s;
 }
 
 inline bool
 SetArgv0ToFullBinaryPath(wchar_t* aArgv[])
 {
   if (!aArgv) {
     return false;
   }
--- a/tools/profiler/core/shared-libraries-win32.cc
+++ b/tools/profiler/core/shared-libraries-win32.cc
@@ -103,17 +103,17 @@ GetVersion(WCHAR* dllPath)
     return EmptyCString();
   }
 
   nsPrintfCString version("%d.%d.%d.%d",
                           vInfo->dwFileVersionMS >> 16,
                           vInfo->dwFileVersionMS & 0xFFFF,
                           vInfo->dwFileVersionLS >> 16,
                           vInfo->dwFileVersionLS & 0xFFFF);
-  return version;
+  return std::move(version);
 }
 
 SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
 {
   SharedLibraryInfo sharedLibraryInfo;
 
   HANDLE hProcess = GetCurrentProcess();
   mozilla::UniquePtr<HMODULE[]> hMods;
--- a/xpcom/glue/FileUtils.cpp
+++ b/xpcom/glue/FileUtils.cpp
@@ -171,25 +171,25 @@ mozilla::GetLibraryName(mozilla::pathstr
   if (aDirectory) {
     fullName.Assign(aDirectory);
     fullName.Append('\\');
   }
   AppendUTF8toUTF16(MakeStringSpan(aLib), fullName);
   if (!strstr(aLib, ".dll")) {
     fullName.AppendLiteral(".dll");
   }
-  return fullName;
+  return std::move(fullName);
 #else
   char* temp = PR_GetLibraryName(aDirectory, aLib);
   if (!temp) {
     return EmptyCString();
   }
   nsAutoCString libname(temp);
   PR_FreeLibraryName(temp);
-  return libname;
+  return std::move(libname);
 #endif
 }
 
 mozilla::PathString
 mozilla::GetLibraryFilePathname(mozilla::pathstr_t aName, PRFuncPtr aAddr)
 {
 #ifdef XP_WIN
   HMODULE handle = GetModuleHandleW(char16ptr_t(aName));
@@ -201,25 +201,25 @@ mozilla::GetLibraryFilePathname(mozilla:
   path.SetLength(MAX_PATH);
   DWORD len = GetModuleFileNameW(handle, char16ptr_t(path.BeginWriting()),
                                  path.Length());
   if (!len) {
     return EmptyString();
   }
 
   path.SetLength(len);
-  return path;
+  return std::move(path);
 #else
   char* temp = PR_GetLibraryFilePathname(aName, aAddr);
   if (!temp) {
     return EmptyCString();
   }
   nsAutoCString path(temp);
   PR_Free(temp); // PR_GetLibraryFilePathname() uses PR_Malloc().
-  return path;
+  return std::move(path);
 #endif
 }
 
 #endif // defined(MOZILLA_INTERNAL_API)
 
 #if defined(LINUX) && !defined(ANDROID)
 
 static const unsigned int bufsize = 4096;