aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-06-14 21:02:42 +0200
committerSebastian Geerken <devnull@localhost>2013-06-14 21:02:42 +0200
commit360c8d716a817b3e7af396174e0315259d78e2fa (patch)
tree4523728030f15d122f06fdbab2fca51191017ac4
parentefe6750f08f61dc3e3930939fd89f29b62484780 (diff)
Small performance optimization.
-rw-r--r--dw/outofflowmgr.hh5
-rw-r--r--dw/textblock.hh2
-rw-r--r--dw/textblock_linebreaking.cc51
3 files changed, 36 insertions, 22 deletions
diff --git a/dw/outofflowmgr.hh b/dw/outofflowmgr.hh
index 01cf563f..97473145 100644
--- a/dw/outofflowmgr.hh
+++ b/dw/outofflowmgr.hh
@@ -277,6 +277,11 @@ public:
inline core::Widget *getWidget (int i) {
return i < leftFloatsAll->size() ? leftFloatsAll->get(i)->widget :
rightFloatsAll->get(i - leftFloatsAll->size())->widget; }
+
+ inline bool affectsLeftBorder (core::Widget *widget) {
+ return widget->getStyle()->vloat == core::style::FLOAT_LEFT; }
+ inline bool affectsRightBorder (core::Widget *widget) {
+ return widget->getStyle()->vloat == core::style::FLOAT_RIGHT; }
};
} // namespace dw
diff --git a/dw/textblock.hh b/dw/textblock.hh
index bcf31d67..8809b5c2 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -598,7 +598,7 @@ protected:
void wrapWordInFlow (int wordIndex, bool wrapAll);
void checkPossibleLighHeightChange (int wordIndex);
void wrapWordOofRef (int wordIndex, bool wrapAll);
- void updateBorders (int wordIndex);
+ void updateBorders (int wordIndex, bool left, bool right);
int searchMinBap (int firstWord, int lastWordm, int penaltyIndex,
bool correctAtEnd);
int considerHyphenation (int firstIndex, int breakPos);
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 3372485e..83ccfc44 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -719,7 +719,7 @@ void Textblock::checkPossibleLighHeightChange (int wordIndex)
}
if (!equalOrGreaterFound)
- updateBorders (wordIndex);
+ updateBorders (wordIndex, true, true);
}
}
@@ -728,37 +728,46 @@ void Textblock::wrapWordOofRef (int wordIndex, bool wrapAll)
assert (containingBlock->outOfFlowMgr);
int y = topOfPossiblyMissingLine (lines->size ());
- containingBlock->outOfFlowMgr->tellPosition
- (words->getRef(wordIndex)->content.widget, y);
+ Widget *widget = words->getRef(wordIndex)->content.widget;
+ containingBlock->outOfFlowMgr->tellPosition (widget, y);
- // Suggestion for better performance: One could ignore OOF
- // references which do not have an effect on borders (e. g. soon
- // absolute positions); and also distinguish between left and right
- // border. OutOfFlowMgr should provide methods for this:
- // affectsLeftBorder and affectsRightBorder.
+ // For better performance: Ignore OOF references which do not have
+ // an effect on borders (e. g. soon absolute positions); and also
+ // distinguish between left and right border.
- updateBorders (wordIndex);
+ bool left = containingBlock->outOfFlowMgr->affectsLeftBorder (widget);
+ bool right = containingBlock->outOfFlowMgr->affectsRightBorder (widget);
+ if (left || right)
+ updateBorders (wordIndex, left, right);
}
/**
* Recalculate borders (due to floats) for new line.
*/
-void Textblock::updateBorders (int wordIndex)
+void Textblock::updateBorders (int wordIndex, bool left, bool right)
{
+ assert (left || right);
+
int y = topOfPossiblyMissingLine (lines->size ());
int h = heightOfPossiblyMissingLine (lines->size ());
- newLineHasFloatLeft =
- containingBlock->outOfFlowMgr->hasFloatLeft (this, y, h, this, wordIndex);
- newLineHasFloatRight =
- containingBlock->outOfFlowMgr->hasFloatRight (this, y, h, this,
- wordIndex);
- newLineLeftBorder =
- containingBlock->outOfFlowMgr->getLeftBorder (this, y, h, this,
- wordIndex);
- newLineRightBorder =
- containingBlock->outOfFlowMgr->getRightBorder (this, y, h, this,
- wordIndex);
+ if (left) {
+ newLineHasFloatLeft =
+ containingBlock->outOfFlowMgr->hasFloatLeft (this, y, h, this,
+ wordIndex);
+ newLineHasFloatRight =
+ containingBlock->outOfFlowMgr->hasFloatRight (this, y, h, this,
+ wordIndex);
+ }
+
+ if (right) {
+ newLineLeftBorder =
+ containingBlock->outOfFlowMgr->getLeftBorder (this, y, h, this,
+ wordIndex);
+ newLineRightBorder =
+ containingBlock->outOfFlowMgr->getRightBorder (this, y, h, this,
+ wordIndex);
+ }
int firstIndex =
lines->size() == 0 ? 0 : lines->getLastRef()->lastWord + 1;