bug 1035323 - remove redundant null-checks in the DetailedGlyphStore code. r=jdaggett
authorJonathan Kew <jkew@mozilla.com>
Tue, 08 Jul 2014 14:56:41 +0100
changeset 192858 d491883232b45d977c74d4dac12684ae338ad7b4
parent 192857 373ec3f226af4cf6329b739b1006e469fa5419a2
child 192859 cd8e323d27c39ab0902d7e626991ea062d5b33ed
push id7663
push userkwierso@gmail.com
push dateWed, 09 Jul 2014 03:08:08 +0000
treeherderfx-team@48de6f4f82af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs1035323
milestone33.0a1
bug 1035323 - remove redundant null-checks in the DetailedGlyphStore code. r=jdaggett
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -6488,39 +6488,30 @@ gfxShapedText::DetailedGlyph *
 gfxShapedText::AllocateDetailedGlyphs(uint32_t aIndex, uint32_t aCount)
 {
     NS_ASSERTION(aIndex < GetLength(), "Index out of range");
 
     if (!mDetailedGlyphs) {
         mDetailedGlyphs = new DetailedGlyphStore();
     }
 
-    DetailedGlyph *details = mDetailedGlyphs->Allocate(aIndex, aCount);
-    if (!details) {
-        GetCharacterGlyphs()[aIndex].SetMissing(0);
-        return nullptr;
-    }
-
-    return details;
+    return mDetailedGlyphs->Allocate(aIndex, aCount);
 }
 
 void
 gfxShapedText::SetGlyphs(uint32_t aIndex, CompressedGlyph aGlyph,
                          const DetailedGlyph *aGlyphs)
 {
     NS_ASSERTION(!aGlyph.IsSimpleGlyph(), "Simple glyphs not handled here");
     NS_ASSERTION(aIndex > 0 || aGlyph.IsLigatureGroupStart(),
                  "First character can't be a ligature continuation!");
 
     uint32_t glyphCount = aGlyph.GetGlyphCount();
     if (glyphCount > 0) {
         DetailedGlyph *details = AllocateDetailedGlyphs(aIndex, glyphCount);
-        if (!details) {
-            return;
-        }
         memcpy(details, aGlyphs, sizeof(DetailedGlyph)*glyphCount);
     }
     GetCharacterGlyphs()[aIndex] = aGlyph;
 }
 
 #define ZWNJ 0x200C
 #define ZWJ  0x200D
 // U+061C ARABIC LETTER MARK is expected to be added to XIDMOD_DEFAULT_IGNORABLE
@@ -6539,19 +6530,16 @@ gfxShapedText::SetMissingGlyph(uint32_t 
     uint8_t category = GetGeneralCategory(aChar);
     if (category >= HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK &&
         category <= HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
     {
         GetCharacterGlyphs()[aIndex].SetComplex(false, true, 0);
     }
 
     DetailedGlyph *details = AllocateDetailedGlyphs(aIndex, 1);
-    if (!details) {
-        return;
-    }
 
     details->mGlyphID = aChar;
     if (IsDefaultIgnorable(aChar)) {
         // Setting advance width to zero will prevent drawing the hexbox
         details->mAdvance = 0;
     } else {
         gfxFloat width =
             std::max(aFont->GetMetrics().aveCharWidth,
@@ -6564,24 +6552,22 @@ gfxShapedText::SetMissingGlyph(uint32_t 
     GetCharacterGlyphs()[aIndex].SetMissing(1);
 }
 
 bool
 gfxShapedText::FilterIfIgnorable(uint32_t aIndex, uint32_t aCh)
 {
     if (IsDefaultIgnorable(aCh)) {
         DetailedGlyph *details = AllocateDetailedGlyphs(aIndex, 1);
-        if (details) {
-            details->mGlyphID = aCh;
-            details->mAdvance = 0;
-            details->mXOffset = 0;
-            details->mYOffset = 0;
-            GetCharacterGlyphs()[aIndex].SetMissing(1);
-            return true;
-        }
+        details->mGlyphID = aCh;
+        details->mAdvance = 0;
+        details->mXOffset = 0;
+        details->mYOffset = 0;
+        GetCharacterGlyphs()[aIndex].SetMissing(1);
+        return true;
     }
     return false;
 }
 
 void
 gfxShapedText::AdjustAdvancesForSyntheticBold(float aSynBoldOffset,
                                               uint32_t aOffset,
                                               uint32_t aLength)
@@ -7651,34 +7637,16 @@ gfxTextRun::CountMissingGlyphs()
     for (i = 0; i < GetLength(); ++i) {
         if (mCharacterGlyphs[i].IsMissing()) {
             ++count;
         }
     }
     return count;
 }
 
-gfxTextRun::DetailedGlyph *
-gfxTextRun::AllocateDetailedGlyphs(uint32_t aIndex, uint32_t aCount)
-{
-    NS_ASSERTION(aIndex < GetLength(), "Index out of range");
-
-    if (!mDetailedGlyphs) {
-        mDetailedGlyphs = new DetailedGlyphStore();
-    }
-
-    DetailedGlyph *details = mDetailedGlyphs->Allocate(aIndex, aCount);
-    if (!details) {
-        mCharacterGlyphs[aIndex].SetMissing(0);
-        return nullptr;
-    }
-
-    return details;
-}
-
 void
 gfxTextRun::CopyGlyphDataFrom(gfxShapedWord *aShapedWord, uint32_t aOffset)
 {
     uint32_t wordLen = aShapedWord->GetLength();
     NS_ASSERTION(aOffset + wordLen <= GetLength(),
                  "word overruns end of textrun!");
 
     CompressedGlyph *charGlyphs = GetCharacterGlyphs();
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -2620,33 +2620,26 @@ protected:
             NS_ASSERTION(mLastUsed != nsTArray<DGRec>::NoIndex,
                          "detailed glyph record missing!");
             return details + mOffsetToIndex[mLastUsed].mIndex;
         }
 
         DetailedGlyph* Allocate(uint32_t aOffset, uint32_t aCount) {
             uint32_t detailIndex = mDetails.Length();
             DetailedGlyph *details = mDetails.AppendElements(aCount);
-            if (!details) {
-                return nullptr;
-            }
             // We normally set up glyph records sequentially, so the common case
             // here is to append new records to the mOffsetToIndex array;
             // test for that before falling back to the InsertElementSorted
             // method.
             if (mOffsetToIndex.Length() == 0 ||
                 aOffset > mOffsetToIndex[mOffsetToIndex.Length() - 1].mOffset) {
-                if (!mOffsetToIndex.AppendElement(DGRec(aOffset, detailIndex))) {
-                    return nullptr;
-                }
+                mOffsetToIndex.AppendElement(DGRec(aOffset, detailIndex));
             } else {
-                if (!mOffsetToIndex.InsertElementSorted(DGRec(aOffset, detailIndex),
-                                                        CompareRecordOffsets())) {
-                    return nullptr;
-                }
+                mOffsetToIndex.InsertElementSorted(DGRec(aOffset, detailIndex),
+                                                   CompareRecordOffsets());
             }
             return details;
         }
 
         size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
             return aMallocSizeOf(this) +
                 mDetails.SizeOfExcludingThis(aMallocSizeOf) +
                 mOffsetToIndex.SizeOfExcludingThis(aMallocSizeOf);
@@ -3452,19 +3445,16 @@ protected:
 
     // Pointer to the array of CompressedGlyph records; must be initialized
     // when the object is constructed.
     CompressedGlyph *mCharacterGlyphs;
 
 private:
     // **** general helpers **** 
 
-    // Allocate aCount DetailedGlyphs for the given index
-    DetailedGlyph *AllocateDetailedGlyphs(uint32_t aCharIndex, uint32_t aCount);
-
     // Get the total advance for a range of glyphs.
     int32_t GetAdvanceForGlyphs(uint32_t aStart, uint32_t aEnd);
 
     // Spacing for characters outside the range aSpacingStart/aSpacingEnd
     // is assumed to be zero; such characters are not passed to aProvider.
     // This is useful to protect aProvider from being passed character indices
     // it is not currently able to handle.
     bool GetAdjustedSpacingArray(uint32_t aStart, uint32_t aEnd,