Bug 410857 - Part 3: Cache the PresContext instead of fetching it for every paragraph. r=jfkthame, a=jcristau
authorMats Palmgren <mats@mozilla.com>
Mon, 20 Feb 2017 17:43:08 +0100
changeset 376329 0fa7c14ad50daff9879dad3571255c542456036f
parent 376328 d83db77b92f8a8160feb9b1e8c4e4ad88994f688
child 376330 2022fb5a3a0e27893bf1749def685a0cb47dcc8c
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame, jcristau
bugs410857
milestone53.0a2
Bug 410857 - Part 3: Cache the PresContext instead of fetching it for every paragraph. r=jfkthame, a=jcristau
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");