Bug 1291483 part 2: Use UniquePtr/MakeUnique more thoroughly in chain-of-custody for gfxFont::mVerticalMetrics. r=jfkthame
☠☠ backed out by fc58b761a05b ☠ ☠
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 09 Mar 2017 16:38:58 -0800
changeset 346871 c8bfaf1927b6e35e2955323c6e8845a6a5216d43
parent 346870 5a0c4791eef57a309aef794490c5ba394923de6a
child 346872 1b2d90a65aecd38969c6b820374fdb785ce8bec3
push id38628
push userdholbert@mozilla.com
push dateFri, 10 Mar 2017 01:08:56 +0000
treeherderautoland@c8bfaf1927b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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
--- 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>
     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);
 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);
     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,