Bug 410857 part 3 - Cache the PresContext instead of fetching it for every paragraph. r=jfkthame
MozReview-Commit-ID: 68cLNSGnpjS
--- 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");