Bug 1485161: Make gfxPlatform::GetDefaultFontName() return nsAutoString, to enable possibility of Return Value Optimization & to address build warning. r=jfkthame
authorDaniel Holbert <dholbert@cs.stanford.edu>
Wed, 22 Aug 2018 13:34:16 +0000
changeset 490585 928dc169698aad907fe9fb9881340a4a88f76851
parent 490584 d99190a5b731a101fe1852a2fa7d9af69e6412f9
child 490586 4e1e283b347e15910c87610577ffeba931de3eeb
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1485161
milestone63.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 1485161: Make gfxPlatform::GetDefaultFontName() return nsAutoString, to enable possibility of Return Value Optimization & to address build warning. r=jfkthame This function uses a nsAutoString internally, and its caller stores its returned value in a nsAutoString. So it's silly for us to have it return a different type (nsString). With this change, the compiler should be able to perform return value optimization and avoid the need for any copying/reallocation of this function's return value. Differential Revision: https://phabricator.services.mozilla.com/D3926
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -1648,27 +1648,30 @@ nsresult
 gfxPlatform::GetStandardFamilyName(const nsAString& aFontName,
                                    nsAString& aFamilyName)
 {
     gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName,
                                                                    aFamilyName);
     return NS_OK;
 }
 
-nsString
+nsAutoString
 gfxPlatform::GetDefaultFontName(const nsACString& aLangGroup,
                                 const nsACString& aGenericFamily)
 {
+    // To benefit from Return Value Optimization, all paths here must return
+    // this one variable:
+    nsAutoString result;
+
     gfxFontFamily* fontFamily = gfxPlatformFontList::PlatformFontList()->
         GetDefaultFontFamily(aLangGroup, aGenericFamily);
-    if (!fontFamily) {
-      return EmptyString();
-    }
-    nsAutoString result;
-    fontFamily->LocalizedName(result);
+    if (fontFamily) {
+      fontFamily->LocalizedName(result);
+    } // (else, leave 'result' empty)
+
     return result;
 }
 
 bool
 gfxPlatform::DownloadableFontsEnabled()
 {
     if (mAllowDownloadableFonts == UNINITIALIZED_VALUE) {
         mAllowDownloadableFonts =
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -372,18 +372,18 @@ public:
 
     /**
      * Returns default font name (localized family name) for aLangGroup and
      * aGenericFamily.  The result is typically the first font in
      * font.name-list.<aGenericFamily>.<aLangGroup>.  However, if it's not
      * available in the system, this may return second or later font in the
      * pref.  If there are no available fonts in the pref, returns empty string.
      */
-    nsString GetDefaultFontName(const nsACString& aLangGroup,
-                                const nsACString& aGenericFamily);
+    nsAutoString GetDefaultFontName(const nsACString& aLangGroup,
+                                    const nsACString& aGenericFamily);
 
     /**
      * Create the appropriate platform font group
      */
     virtual gfxFontGroup*
     CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
                     const gfxFontStyle *aStyle,
                     gfxTextPerfMetrics* aTextPerf,