Bug 410857 part 3 - Cache the PresContext instead of fetching it for every paragraph. r=jfkthame draft
authorMats Palmgren <mats@mozilla.com>
Mon, 20 Feb 2017 00:34:13 +0100
changeset 486793 77439aad6f37ab71d85211d1da6bbcd7c5f137ca
parent 486792 6ec85ae1516a3c77740d58c4932740a03251dad8
child 486794 1456325f3d37ffc2406a750a468966f0aa0befc7
push id46061
push usermpalmgren@mozilla.com
push dateMon, 20 Feb 2017 00:13:17 +0000
reviewersjfkthame
bugs410857
milestone54.0a1
Bug 410857 part 3 - Cache the PresContext instead of fetching it for every paragraph. r=jfkthame MozReview-Commit-ID: 68cLNSGnpjS
layout/base/nsBidiPresUtils.cpp
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -128,29 +128,32 @@ GetBidiControl(nsStyleContext* aStyleCon
 
 struct MOZ_STACK_CLASS BidiParagraphData
 {
   nsAutoString        mBuffer;
   AutoTArray<char16_t, 16> mEmbeddingStack;
   AutoTArray<nsIFrame*, 16> mLogicalFrames;
   AutoTArray<nsLineBox*, 16> mLinePerFrame;
   nsDataHashtable<nsISupportsHashKey, int32_t> mContentToFrameIndex;
+  // Cached presentation context for the frames we're processing.
+  nsPresContext*      mPresContext;
   bool                mIsVisual;
   nsBidiLevel         mParaLevel;
   nsIContent*         mPrevContent;
   nsBidi              mBidiEngine;
   nsIFrame*           mPrevFrame;
 
-  void Init(nsBlockFrame *aBlockFrame)
+  void Init(nsBlockFrame* aBlockFrame)
   {
     mPrevContent = nullptr;
 
     mParaLevel = nsBidiPresUtils::BidiLevelFromStyle(aBlockFrame->StyleContext());
 
-    mIsVisual = aBlockFrame->PresContext()->IsVisualMode();
+    mPresContext = aBlockFrame->PresContext();
+    mIsVisual = mPresContext->IsVisualMode();
     if (mIsVisual) {
       /**
        * Drill up in content to detect whether this is an element that needs to
        * be rendered with logical order even on visual pages.
        *
        * We always use logical order on form controls, firstly so that text
        * entry will be in logical order, but also because visual pages were
        * written with the assumption that even if the browser had no support
@@ -708,18 +711,16 @@ nsBidiPresUtils::Resolve(nsBlockFrame* a
 
   return ResolveParagraph(aBlockFrame, &bpd);
 }
 
 nsresult
 nsBidiPresUtils::ResolveParagraph(nsBlockFrame* aBlockFrame,
                                   BidiParagraphData* aBpd)
 {
-  nsPresContext *presContext = aBlockFrame->PresContext();
-
   if (aBpd->BufferLength() < 1) {
     return NS_OK;
   }
   aBpd->mBuffer.ReplaceChar(kSeparators, kSpace);
 
   int32_t runCount;
 
   nsresult rv = aBpd->SetPara();
@@ -737,17 +738,17 @@ nsBidiPresUtils::ResolveParagraph(nsBloc
   int32_t     frameIndex     = -1;  // index to the frames in mLogicalFrames
   int32_t     frameCount     = aBpd->FrameCount();
   int32_t     contentOffset  = 0;   // offset of current frame in its content node
   bool        isTextFrame    = false;
   nsIFrame*   frame = nullptr;
   nsIContent* content = nullptr;
   int32_t     contentTextLength = 0;
 
-  FramePropertyTable *propTable = presContext->PropertyTable();
+  FramePropertyTable* propTable = aBpd->mPresContext->PropertyTable();
   nsLineBox* currentLine = nullptr;
   
 #ifdef DEBUG
 #ifdef NOISY_BIDI
   printf("Before Resolve(), aBlockFrame=0x%p, mBuffer='%s', frameCount=%d, runCount=%d\n",
          (void*)aBlockFrame, NS_ConvertUTF16toUTF8(aBpd->mBuffer).get(), frameCount, runCount);
 #ifdef REALLY_NOISY_BIDI
   printf(" block frame tree=:\n");