Index: Source/core/rendering/svg/SVGTextQuery.cpp |
diff --git a/Source/core/rendering/svg/SVGTextQuery.cpp b/Source/core/rendering/svg/SVGTextQuery.cpp |
index f5ead0d43661f2ec0f636f48021b511100a0b748..7b9fcb95171fa59a0034ff11510e4f1cbacf750b 100644 |
--- a/Source/core/rendering/svg/SVGTextQuery.cpp |
+++ b/Source/core/rendering/svg/SVGTextQuery.cpp |
@@ -38,13 +38,36 @@ struct SVGTextQuery::Data { |
, processedCharacters(0) |
, textRenderer(0) |
, textBox(0) |
+ , ligatureAdjustmentLastStartPositionQuery(-1) |
+ , ligatureAdjustmentLastEndPositionQuery(-1) |
+ , ligatureAdjustmentLastStartPositionResult(-1) |
+ , ligatureAdjustmentLastEndPositionResult(-1) |
{ |
} |
+ void setupForTextBox(const SVGInlineTextBox* newTextBox) |
+ { |
+ textBox = newTextBox; |
+ textRenderer = &toRenderSVGInlineText(textBox->textRenderer()); |
+ ASSERT(textRenderer->style()); |
+ ASSERT(textRenderer->style()->svgStyle()); |
+ |
+ isVerticalText = textRenderer->style()->svgStyle()->isVerticalWritingMode(); |
+ |
+ // Invalidate the ligature-adjustment cache. |
pdr.
2014/06/24 21:18:48
Is it possible to invalidate the cache when it rea
fs
2014/06/25 10:29:49
That pretty much what it does ATM - in the loop in
|
+ ligatureAdjustmentLastStartPositionQuery = ligatureAdjustmentLastEndPositionQuery = -1; |
+ ligatureAdjustmentLastStartPositionResult = ligatureAdjustmentLastEndPositionResult = -1; |
+ } |
+ |
bool isVerticalText; |
unsigned processedCharacters; |
RenderSVGInlineText* textRenderer; |
const SVGInlineTextBox* textBox; |
+ // Ligature adjustment cache. |
pdr.
2014/06/24 21:18:48
The cache key is pretty much {startPosition, proce
fs
2014/06/25 10:29:49
I suppose there could be some merit to that... To
|
+ int ligatureAdjustmentLastStartPositionQuery; |
+ int ligatureAdjustmentLastEndPositionQuery; |
+ int ligatureAdjustmentLastStartPositionResult; |
+ int ligatureAdjustmentLastEndPositionResult; |
}; |
static inline InlineFlowBox* flowBoxForRenderer(RenderObject* renderer) |
@@ -111,12 +134,8 @@ bool SVGTextQuery::executeQuery(Data* queryData, ProcessTextFragmentCallback fra |
// Loop over all text boxes |
for (unsigned textBoxPosition = 0; textBoxPosition < textBoxCount; ++textBoxPosition) { |
- queryData->textBox = m_textBoxes.at(textBoxPosition); |
- queryData->textRenderer = &toRenderSVGInlineText(queryData->textBox->textRenderer()); |
- ASSERT(queryData->textRenderer->style()); |
- ASSERT(queryData->textRenderer->style()->svgStyle()); |
+ queryData->setupForTextBox(m_textBoxes.at(textBoxPosition)); |
- queryData->isVerticalText = queryData->textRenderer->style()->svgStyle()->isVerticalWritingMode(); |
const Vector<SVGTextFragment>& fragments = queryData->textBox->textFragments(); |
// Loop over all text fragments in this text box, firing a callback for each. |
@@ -146,7 +165,7 @@ bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, |
if (startPosition >= endPosition) |
return false; |
- modifyStartEndPositionsRespectingLigatures(queryData, startPosition, endPosition); |
+ modifyStartEndPositionsRespectingLigaturesCached(queryData, startPosition, endPosition); |
pdr.
2014/06/24 21:18:48
This name was confusing until I read the implement
fs
2014/06/25 10:29:49
Although it didn't like having the additional indi
|
if (!queryData->textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition)) |
return false; |
@@ -154,6 +173,23 @@ bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, |
return true; |
} |
+void SVGTextQuery::modifyStartEndPositionsRespectingLigaturesCached(Data* queryData, int& startPosition, int& endPosition) const |
+{ |
+ if (queryData->ligatureAdjustmentLastStartPositionQuery == startPosition && queryData->ligatureAdjustmentLastEndPositionQuery == endPosition) { |
+ startPosition = queryData->ligatureAdjustmentLastStartPositionResult; |
+ endPosition = queryData->ligatureAdjustmentLastEndPositionResult; |
+ return; |
+ } |
+ |
+ queryData->ligatureAdjustmentLastStartPositionQuery = startPosition; |
+ queryData->ligatureAdjustmentLastEndPositionQuery = endPosition; |
+ |
+ modifyStartEndPositionsRespectingLigatures(queryData, startPosition, endPosition); |
+ |
+ queryData->ligatureAdjustmentLastStartPositionResult = startPosition; |
+ queryData->ligatureAdjustmentLastEndPositionResult = endPosition; |
+} |
+ |
void SVGTextQuery::modifyStartEndPositionsRespectingLigatures(Data* queryData, int& startPosition, int& endPosition) const |
{ |
SVGTextLayoutAttributes* layoutAttributes = queryData->textRenderer->layoutAttributes(); |