Bug 1291483 part 2: Use UniquePtr/MakeUnique more thoroughly in chain-of-custody for gfxFont::mVerticalMetrics. r=jfkthame
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 09 Mar 2017 16:38:58 -0800
changeset 347043 2f96904d7b3ae012d17e25458f460f8de6cd5978
parent 347042 08753d5d8f1a05dedce9f91887a1e5426f35f8c0
child 347044 7a7d6e9b8329d2806f985836c201a69503e9b24e
push id31490
push usercbook@mozilla.com
push dateMon, 13 Mar 2017 14:19:54 +0000
treeherdermozilla-central@419c70029023 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1291483
milestone55.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 1291483 part 2: Use UniquePtr/MakeUnique more thoroughly in chain-of-custody for gfxFont::mVerticalMetrics. r=jfkthame This member-var has type 'UniquePtr', but (up until this patch) its value is set up using "new" and raw pointers. This patch improves that codepath by using UniquePtr & MakeUnique, for stronger ownership guarantees. MozReview-Commit-ID: KWZVpvr9bYj
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -3637,27 +3637,27 @@ gfxFont::SanitizeMetrics(gfxFont::Metric
 // fail, as we've already decided this is a valid font. We do not have the
 // option of marking it invalid (as can happen if we're unable to read
 // horizontal metrics), because that could break a font that we're already
 // using for horizontal text.
 // So we will synthesize *something* usable here even if there aren't any of the
 // usual font tables (which can happen in the case of a legacy bitmap or Type1
 // font for which the platform-specific backend used platform APIs instead of
 // sfnt tables to create the horizontal metrics).
-const gfxFont::Metrics*
+UniquePtr<const gfxFont::Metrics>
 gfxFont::CreateVerticalMetrics()
 {
     const uint32_t kHheaTableTag = TRUETYPE_TAG('h','h','e','a');
     const uint32_t kVheaTableTag = TRUETYPE_TAG('v','h','e','a');
     const uint32_t kPostTableTag = TRUETYPE_TAG('p','o','s','t');
     const uint32_t kOS_2TableTag = TRUETYPE_TAG('O','S','/','2');
     uint32_t len;
 
-    Metrics* metrics = new Metrics;
-    ::memset(metrics, 0, sizeof(Metrics));
+    UniquePtr<Metrics> metrics = MakeUnique<Metrics>();
+    ::memset(metrics.get(), 0, sizeof(Metrics));
 
     // Some basic defaults, in case the font lacks any real metrics tables.
     // TODO: consider what rounding (if any) we should apply to these.
     metrics->emHeight = GetAdjustedSize();
     metrics->emAscent = metrics->emHeight / 2;
     metrics->emDescent = metrics->emHeight - metrics->emAscent;
 
     metrics->maxAscent = metrics->emAscent;
@@ -3792,17 +3792,17 @@ gfxFont::CreateVerticalMetrics()
 
     // Somewhat arbitrary values for now, subject to future refinement...
     metrics->spaceWidth = metrics->aveCharWidth;
     metrics->zeroOrAveCharWidth = metrics->aveCharWidth;
     metrics->maxHeight = metrics->maxAscent + metrics->maxDescent;
     metrics->xHeight = metrics->emHeight / 2;
     metrics->capHeight = metrics->maxAscent;
 
-    return metrics;
+    return Move(metrics);
 }
 
 gfxFloat
 gfxFont::SynthesizeSpaceWidth(uint32_t aCh)
 {
     // return an appropriate width for various Unicode space characters
     // that we "fake" if they're not actually present in the font;
     // returns negative value if the char is not a known space.
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -1546,17 +1546,17 @@ public:
     };
 
     const Metrics& GetMetrics(Orientation aOrientation)
     {
         if (aOrientation == eHorizontal) {
             return GetHorizontalMetrics();
         }
         if (!mVerticalMetrics) {
-            mVerticalMetrics.reset(CreateVerticalMetrics());
+            mVerticalMetrics = CreateVerticalMetrics();
         }
         return *mVerticalMetrics;
     }
 
     /**
      * We let layout specify spacing on either side of any
      * character. We need to specify both before and after
      * spacing so that substring measurement can do the right things.
@@ -1863,17 +1863,17 @@ public:
     /**
      * Return the reference cairo_t object from aDT.
      */
     static cairo_t* RefCairo(mozilla::gfx::DrawTarget* aDT);
 
 protected:
     virtual const Metrics& GetHorizontalMetrics() = 0;
 
-    const Metrics* CreateVerticalMetrics();
+    mozilla::UniquePtr<const Metrics> CreateVerticalMetrics();
 
     // Output a single glyph at *aPt, which is updated by the glyph's advance.
     // Normal glyphs are simply accumulated in aBuffer until it is full and
     // gets flushed, but SVG or color-font glyphs will instead be rendered
     // directly to the destination (found from the buffer's parameters).
     void DrawOneGlyph(uint32_t           aGlyphID,
                       double             aAdvance,
                       gfxPoint          *aPt,