Bug 1528758 - No need for a null-check before calling hb_*_destroy functions, as they do it internally. r=jrmuizel
authorJonathan Kew <jkew@mozilla.com>
Mon, 18 Feb 2019 17:16:22 +0000
changeset 459807 b3f5c1b6b44d8f23515387d5820f71da566a81bd
parent 459800 c590fd06f7cb325e3b446f7cd5fb98c6d0a26ad1
child 459808 cfb1a7fbbfa7f43de57b4e9fcf629aec8b06a54c
push id35574
push usercbrindusan@mozilla.com
push dateTue, 19 Feb 2019 04:38:09 +0000
treeherdermozilla-central@8231f78228bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1528758
milestone67.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 1528758 - No need for a null-check before calling hb_*_destroy functions, as they do it internally. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D20177
gfx/thebes/gfxFontEntry.cpp
gfx/thebes/gfxFontEntry.h
gfx/thebes/gfxFontUtils.cpp
gfx/thebes/gfxHarfBuzzShaper.cpp
gfx/thebes/gfxMacPlatformFontList.h
--- a/gfx/thebes/gfxFontEntry.cpp
+++ b/gfx/thebes/gfxFontEntry.cpp
@@ -113,23 +113,18 @@ gfxFontEntry::gfxFontEntry(const nsACStr
       mCheckedForVariationAxes(false) {
   memset(&mDefaultSubSpaceFeatures, 0, sizeof(mDefaultSubSpaceFeatures));
   memset(&mNonDefaultSubSpaceFeatures, 0, sizeof(mNonDefaultSubSpaceFeatures));
 }
 
 gfxFontEntry::~gfxFontEntry() {
   // Should not be dropped by stylo
   MOZ_ASSERT(NS_IsMainThread());
-  if (mCOLR) {
-    hb_blob_destroy(mCOLR);
-  }
-
-  if (mCPAL) {
-    hb_blob_destroy(mCPAL);
-  }
+  hb_blob_destroy(mCOLR);
+  hb_blob_destroy(mCPAL);
 
   // For downloaded fonts, we need to tell the user font cache that this
   // entry is being deleted.
   if (mIsDataUserFont) {
     gfxUserFontSet::UserFontCache::ForgetFont(this);
   }
 
   if (mFeatureInputs) {
@@ -463,17 +458,17 @@ hb_blob_t* gfxFontEntry::FontTableHashEn
 
 void gfxFontEntry::FontTableHashEntry::Clear() {
   // If the FontTableBlobData is managing the hash entry, then the blob is
   // not owned by this HashEntry; otherwise there is strong reference to the
   // blob that must be removed.
   if (mSharedBlobData) {
     mSharedBlobData->ForgetHashEntry();
     mSharedBlobData = nullptr;
-  } else if (mBlob) {
+  } else {
     hb_blob_destroy(mBlob);
   }
   mBlob = nullptr;
 }
 
 // a hb_destroy_func for hb_blob_create
 
 /* static */ void gfxFontEntry::FontTableHashEntry::DeleteFontTableBlobData(
--- a/gfx/thebes/gfxFontEntry.h
+++ b/gfx/thebes/gfxFontEntry.h
@@ -262,19 +262,17 @@ class gfxFontEntry {
   // Stack-based utility to return a specified table, automatically releasing
   // the blob when the AutoTable goes out of scope.
   class AutoTable {
    public:
     AutoTable(gfxFontEntry* aFontEntry, uint32_t aTag) {
       mBlob = aFontEntry->GetFontTable(aTag);
     }
     ~AutoTable() {
-      if (mBlob) {
-        hb_blob_destroy(mBlob);
-      }
+      hb_blob_destroy(mBlob);
     }
     operator hb_blob_t*() const { return mBlob; }
 
    private:
     hb_blob_t* mBlob;
     // not implemented:
     AutoTable(const AutoTable&) = delete;
     AutoTable& operator=(const AutoTable&) = delete;
--- a/gfx/thebes/gfxFontUtils.cpp
+++ b/gfx/thebes/gfxFontUtils.cpp
@@ -1765,19 +1765,17 @@ void gfxFontUtils::GetVariationInstances
   };
 
   // Helper to ensure we free a font table when we return.
   class AutoHBBlob {
    public:
     explicit AutoHBBlob(hb_blob_t* aBlob) : mBlob(aBlob) {}
 
     ~AutoHBBlob() {
-      if (mBlob) {
-        hb_blob_destroy(mBlob);
-      }
+      hb_blob_destroy(mBlob);
     }
 
     operator hb_blob_t*() { return mBlob; }
 
    private:
     hb_blob_t* const mBlob;
   };
 
--- a/gfx/thebes/gfxHarfBuzzShaper.cpp
+++ b/gfx/thebes/gfxHarfBuzzShaper.cpp
@@ -61,46 +61,27 @@ gfxHarfBuzzShaper::gfxHarfBuzzShaper(gfx
       mUseFontGlyphWidths(aFont->ProvidesGlyphWidths()),
       mInitialized(false),
       mVerticalInitialized(false),
       mUseVerticalPresentationForms(false),
       mLoadedLocaGlyf(false),
       mLocaLongOffsets(false) {}
 
 gfxHarfBuzzShaper::~gfxHarfBuzzShaper() {
-  if (mCmapTable) {
-    hb_blob_destroy(mCmapTable);
-  }
-  if (mHmtxTable) {
-    hb_blob_destroy(mHmtxTable);
-  }
-  if (mKernTable) {
-    hb_blob_destroy(mKernTable);
-  }
-  if (mVmtxTable) {
-    hb_blob_destroy(mVmtxTable);
-  }
-  if (mVORGTable) {
-    hb_blob_destroy(mVORGTable);
-  }
-  if (mLocaTable) {
-    hb_blob_destroy(mLocaTable);
-  }
-  if (mGlyfTable) {
-    hb_blob_destroy(mGlyfTable);
-  }
-  if (mHBFont) {
-    hb_font_destroy(mHBFont);
-  }
-  if (mHBFace) {
-    hb_face_destroy(mHBFace);
-  }
-  if (mBuffer) {
-    hb_buffer_destroy(mBuffer);
-  }
+  // hb_*_destroy functions are safe to call on nullptr
+  hb_blob_destroy(mCmapTable);
+  hb_blob_destroy(mHmtxTable);
+  hb_blob_destroy(mKernTable);
+  hb_blob_destroy(mVmtxTable);
+  hb_blob_destroy(mVORGTable);
+  hb_blob_destroy(mLocaTable);
+  hb_blob_destroy(mGlyfTable);
+  hb_font_destroy(mHBFont);
+  hb_face_destroy(mHBFace);
+  hb_buffer_destroy(mBuffer);
 }
 
 #define UNICODE_BMP_LIMIT 0x10000
 
 hb_codepoint_t gfxHarfBuzzShaper::GetNominalGlyph(
     hb_codepoint_t unicode) const {
   hb_codepoint_t gid = 0;
 
--- a/gfx/thebes/gfxMacPlatformFontList.h
+++ b/gfx/thebes/gfxMacPlatformFontList.h
@@ -35,19 +35,17 @@ class MacOSFontEntry : public gfxFontEnt
                  bool aIsStandardFace = false, double aSizeHint = 0.0);
 
   // for use with data fonts
   MacOSFontEntry(const nsACString& aPostscriptName, CGFontRef aFontRef,
                  WeightRange aWeight, StretchRange aStretch,
                  SlantStyleRange aStyle, bool aIsDataUserFont, bool aIsLocal);
 
   virtual ~MacOSFontEntry() {
-    if (mTrakTable) {
-      hb_blob_destroy(mTrakTable);
-    }
+    hb_blob_destroy(mTrakTable);
     ::CGFontRelease(mFontRef);
   }
 
   gfxFontEntry* Clone() const override;
 
   CGFontRef GetFontRef();
 
   // override gfxFontEntry table access function to bypass table cache,