The following is a reworked version of yesterday's patch.
It separates the three foo_fill and row.x from Row into their own struct
RowMetrics. The four of them are used toghether and in three places:
getColumnNearX, getCursorX and rowpainter. These three operations are
user-interaction related and thus costly per se.
Moreover, we should improve initial rebreaking time.
The advantages are:
* reduced row cache size (from 46 bytes to 30 in i386)
* the possibility to compute them on a second step after the whole
rebreaking has been done, fixing most of the obvious rebreaking bugs
present in cvs.
I'd like to apply it if no one objects.
Alfredo
? ChangeLog-old
? PosIterator.C-save
? PosIterator.h-save
? bfri.C
? textcursor.C-save
? textcursor.h-save
? insets/insetcollapsable-save.C
? insets/insettext-save.C
Index: Bidi.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/Bidi.C,v
retrieving revision 1.3
diff -u -p -u -r1.3 Bidi.C
--- Bidi.C 13 Nov 2003 13:43:35 -0000 1.3
+++ Bidi.C 1 Mar 2004 11:12:47 -0000
@@ -52,7 +52,7 @@ bool Bidi::same_direction() const
void Bidi::computeTables(Paragraph const & par,
- Buffer const & buf, Row & row)
+ Buffer const & buf, Row const & row)
{
same_direction_ = true;
if (!lyxrc.rtl_support) {
Index: Bidi.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/Bidi.h,v
retrieving revision 1.1
diff -u -p -u -r1.1 Bidi.h
--- Bidi.h 23 Oct 2003 13:28:44 -0000 1.1
+++ Bidi.h 1 Mar 2004 11:12:47 -0000
@@ -45,7 +45,7 @@ struct Bidi {
bool same_direction() const;
///
void computeTables(Paragraph const & par,
- Buffer const &, Row & row);
+ Buffer const &, Row const & row);
private:
///
bool same_direction_;
Index: lyxrow.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxrow.C,v
retrieving revision 1.37
diff -u -p -u -r1.37 lyxrow.C
--- lyxrow.C 27 Feb 2004 09:18:01 -0000 1.37
+++ lyxrow.C 1 Mar 2004 11:12:47 -0000
@@ -24,15 +24,13 @@ using lyx::pos_type;
Row::Row()
: pos_(0), end_(0), height_(0), width_(0), y_offset_(0),
- ascent_of_text_(0), baseline_(0),
- x_(0), fill_separator_(0), fill_hfill_(0), fill_label_hfill_(0)
+ ascent_of_text_(0), baseline_(0)
{}
Row::Row(pos_type pos)
: pos_(pos), end_(0), height_(0), width_(0), y_offset_(0),
- ascent_of_text_(0), baseline_(0),
- x_(0), fill_separator_(0), fill_hfill_(0), fill_label_hfill_(0)
+ ascent_of_text_(0), baseline_(0)
{}
@@ -105,54 +103,6 @@ void Row::baseline(unsigned int b)
unsigned int Row::baseline() const
{
return baseline_;
-}
-
-
-float Row::x() const
-{
- return x_;
-}
-
-
-void Row::x(float f)
-{
- x_ = f;
-}
-
-
-float Row::fill_separator() const
-{
- return fill_separator_;
-}
-
-
-void Row::fill_separator(float f)
-{
- fill_separator_ = f;
-}
-
-
-float Row::fill_hfill() const
-{
- return fill_hfill_;
-}
-
-
-void Row::fill_hfill(float f)
-{
- fill_hfill_ = f;
-}
-
-
-float Row::fill_label_hfill() const
-{
- return fill_label_hfill_;
-}
-
-
-void Row::fill_label_hfill(float f)
-{
- fill_label_hfill_ = f;
}
Index: lyxrow.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxrow.h,v
retrieving revision 1.40
diff -u -p -u -r1.40 lyxrow.h
--- lyxrow.h 27 Feb 2004 09:18:01 -0000 1.40
+++ lyxrow.h 1 Mar 2004 11:12:47 -0000
@@ -58,24 +58,9 @@ public:
unsigned int y_offset() const { return y_offset_; }
/// cache the y position
void y_offset(unsigned int newy) { y_offset_ = newy; }
- ///
- float x() const;
- ///
- void x(float);
- ///
- float fill_separator() const;
- ///
- void fill_separator(float);
- ///
- float fill_hfill() const;
- ///
- void fill_hfill(float);
- ///
- float fill_label_hfill() const;
- ///
- void fill_label_hfill(float);
/// current debugging only
void dump(const char * = "") const;
+
private:
/// first pos covered by this row
lyx::pos_type pos_;
@@ -93,14 +78,19 @@ private:
unsigned int top_of_text_;
///
unsigned int baseline_;
- /// offet from left border
- float x_;
+};
+
+
+struct RowMetrics {
+ ///
+ double separator;
///
- float fill_separator_;
+ double hfill;
///
- float fill_hfill_;
+ double label_hfill;
///
- float fill_label_hfill_;
+ double x;
};
+
#endif
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.297
diff -u -p -u -r1.297 lyxtext.h
--- lyxtext.h 1 Mar 2004 10:46:58 -0000 1.297
+++ lyxtext.h 1 Mar 2004 11:12:47 -0000
@@ -41,11 +41,11 @@ class MetricsInfo;
class PainterInfo;
class Paragraph;
class Row;
+class RowMetrics;
class Spacing;
class UpdatableInset;
class VSpace;
-
/// This class encapsulates the main text data and operations in LyX
class LyXText {
public:
@@ -320,7 +320,8 @@ public:
/** this calculates the specified parameters. needed when setting
* the cursor and when creating a visible row */
- void prepareToPrint(ParagraphList::iterator pit, Row & row) const;
+ RowMetrics
+ prepareToPrint(ParagraphList::iterator pit, Row const & row) const;
/// access to our paragraphs
ParagraphList & paragraphs() const;
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.120
diff -u -p -u -r1.120 rowpainter.C
--- rowpainter.C 27 Feb 2004 09:18:02 -0000 1.120
+++ rowpainter.C 1 Mar 2004 11:12:48 -0000
@@ -120,16 +120,16 @@ RowPainter::RowPainter(BufferView const
ParagraphList::iterator pit, RowList::iterator rit,
int xo, int yo)
: bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit),
- pit_(pit), xo_(xo), yo_(yo), x_(row_.x()),
- width_(text_.textWidth()),
- separator_(row_.fill_separator()),
- hfill_(row_.fill_hfill()),
- label_hfill_(row_.fill_label_hfill())
+ pit_(pit), xo_(xo), yo_(yo), width_(text_.width)
{
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo
// << " pit->y: " << pit_->y
// << " row: " << (pit_->size() ? pit_->getChar(row_.pos()) : 'X') << endl;
- x_ += xo_;
+ RowMetrics m = text_.prepareToPrint(pit, row_);
+ x_ = m.x + xo_;
+ separator_ = m.separator;
+ hfill_ = m.hfill;
+ label_hfill_ = m.label_hfill;
// background has already been cleared.
if (&text_ == bv_.text())
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.544
diff -u -p -u -r1.544 text.C
--- text.C 1 Mar 2004 10:46:58 -0000 1.544
+++ text.C 1 Mar 2004 11:12:50 -0000
@@ -368,6 +368,7 @@ int LyXText::leftMargin(ParagraphList::i
break;
}
}
+
if (!pit->params().leftIndent().zero())
x += pit->params().leftIndent().inPixels(textWidth());
@@ -1005,19 +1006,23 @@ void LyXText::charInserted()
}
-void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
+RowMetrics
+LyXText::prepareToPrint(ParagraphList::iterator pit, Row const & row) const
{
- double w = textWidth() - row.width();
- double fill_hfill = 0;
- double fill_label_hfill = 0;
- double fill_separator = 0;
- double x = 0;
+ RowMetrics result;
+
+ double w = width - row.width();
+
+ result.hfill = 0;
+ result.label_hfill = 0;
+ result.separator = 0;
+ result.x = 0;
bool const is_rtl = isRTL(*pit);
if (is_rtl)
- x = rightMargin(*pit);
+ result.x = rightMargin(*pit);
else
- x = leftMargin(pit, row.pos());
+ result.x = leftMargin(pit, row.pos());
// is there a manual margin with a manual label
LyXLayout_ptr const & layout = pit->layout();
@@ -1036,7 +1041,7 @@ void LyXText::prepareToPrint(ParagraphLi
++nlh;
if (nlh && !pit->getLabelWidthString().empty())
- fill_label_hfill = labelFill(pit, row) / double(nlh);
+ result.label_hfill = labelFill(pit, row) / double(nlh);
}
// are there any hfills in the row?
@@ -1044,7 +1049,7 @@ void LyXText::prepareToPrint(ParagraphLi
if (nh) {
if (w > 0)
- fill_hfill = w / nh;
+ result.hfill = w / nh;
// we don't have to look at the alignment if it is ALIGN_LEFT and
// if the row is already larger then the permitted width as then
// we force the LEFT_ALIGN'edness!
@@ -1085,17 +1090,17 @@ void LyXText::prepareToPrint(ParagraphLi
&& !pit->isNewline(row.endpos() - 1)
&& !disp_inset
) {
- fill_separator = w / ns;
+ result.separator = w / ns;
} else if (is_rtl) {
- x += w;
+ result.x += w;
}
break;
}
case LYX_ALIGN_RIGHT:
- x += w;
+ result.x += w;
break;
case LYX_ALIGN_CENTER:
- x += w / 2;
+ result.x += w / 2;
break;
}
}
@@ -1108,16 +1113,13 @@ void LyXText::prepareToPrint(ParagraphLi
if (body_pos > 0
&& (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
{
- x += font_metrics::width(layout->labelsep, getLabelFont(pit));
+ result.x += font_metrics::width(layout->labelsep, getLabelFont(pit));
if (body_pos <= end)
- x += fill_label_hfill;
+ result.x += result.label_hfill;
}
}
- row.fill_hfill(fill_hfill);
- row.fill_label_hfill(fill_label_hfill);
- row.fill_separator(fill_separator);
- row.x(x);
+ return result;
}
@@ -1578,7 +1580,6 @@ void LyXText::redoParagraphInternal(Para
Row row(z);
rowBreakPoint(pit, row);
setRowWidth(pit, row);
- prepareToPrint(pit, row);
setHeightOfRow(pit, row);
row.y_offset(pit->height);
pit->rows.push_back(row);
@@ -1817,13 +1818,15 @@ int LyXText::cursorX(CursorSlice const &
ParagraphList::iterator pit = getPar(cur);
if (pit->rows.empty())
return xo_;
- Row const & row = *pit->getRow(cur.pos());
- pos_type pos = cur.pos();
- pos_type cursor_vpos = 0;
- double x = row.x();
- double fill_separator = row.fill_separator();
- double fill_hfill = row.fill_hfill();
- double fill_label_hfill = row.fill_label_hfill();
+ Row const & row = *pit->getRow(cur.pos());
+
+
+ pos_type pos = cur.pos();
+ pos_type cursor_vpos = 0;
+
+ RowMetrics const m = prepareToPrint(pit, row);
+ double x = m.x;
+
pos_type const row_pos = row.pos();
pos_type const end = row.endpos();
@@ -1848,7 +1851,7 @@ int LyXText::cursorX(CursorSlice const &
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
- x += fill_label_hfill
+ x += m.label_hfill
+ font_metrics::width(pit->layout()->labelsep,
getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1))
@@ -1858,13 +1861,13 @@ int LyXText::cursorX(CursorSlice const &
if (hfillExpansion(*pit, row, pos)) {
x += singleWidth(pit, pos);
if (pos >= body_pos)
- x += fill_hfill;
+ x += m.hfill;
else
- x += fill_label_hfill;
+ x += m.label_hfill;
} else if (pit->isSeparator(pos)) {
x += singleWidth(pit, pos);
if (pos >= body_pos)
- x += fill_separator;
+ x += m.separator;
} else
x += singleWidth(pit, pos);
}
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.550
diff -u -p -u -r1.550 text2.C
--- text2.C 20 Feb 2004 17:19:51 -0000 1.550
+++ text2.C 1 Mar 2004 11:12:51 -0000
@@ -87,7 +87,7 @@ void LyXText::init(BufferView * bv)
for (ParagraphList::iterator pit = beg; pit != end; ++pit)
pit->rows.clear();
- width = 0;
+ width = bv->workWidth();
height = 0;
current_font = getFont(beg, 0);
@@ -1197,11 +1197,8 @@ pos_type LyXText::getColumnNearX(Paragra
Row const & row, int & x, bool & boundary) const
{
x -= xo_;
- double tmpx = row.x();
- double fill_separator = row.fill_separator();
- double fill_hfill = row.fill_hfill();
- double fill_label_hfill = row.fill_label_hfill();
-
+ RowMetrics const r = prepareToPrint(pit, row);
+
pos_type vc = row.pos();
pos_type end = row.endpos();
pos_type c = 0;
@@ -1210,6 +1207,8 @@ pos_type LyXText::getColumnNearX(Paragra
bool left_side = false;
pos_type body_pos = pit->beginOfBody();
+
+ double tmpx = r.x;
double last_tmpx = tmpx;
if (body_pos > 0 &&
@@ -1226,7 +1225,7 @@ pos_type LyXText::getColumnNearX(Paragra
c = bidi.vis2log(vc);
last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) {
- tmpx += fill_label_hfill +
+ tmpx += r.label_hfill +
font_metrics::width(layout->labelsep, getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1))
tmpx -= singleWidth(pit, body_pos - 1);
@@ -1235,13 +1234,13 @@ pos_type LyXText::getColumnNearX(Paragra
if (hfillExpansion(*pit, row, c)) {
tmpx += singleWidth(pit, c);
if (c >= body_pos)
- tmpx += fill_hfill;
+ tmpx += r.hfill;
else
- tmpx += fill_label_hfill;
+ tmpx += r.label_hfill;
} else if (pit->isSeparator(c)) {
tmpx += singleWidth(pit, c);
if (c >= body_pos)
- tmpx += fill_separator;
+ tmpx += r.separator;
} else {
tmpx += singleWidth(pit, c);
}