From: André Pönitz Date: Thu, 16 Oct 2003 16:19:56 +0000 (+0000) Subject: make updateRowPositions() a bit faster. X-Git-Tag: 1.6.10~15940 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9ed14b41fa5a4775830f74e029a320e8bb93b10b;p=features.git make updateRowPositions() a bit faster. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7926 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 16f26dc97c..33e73fbd90 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,16 @@ * lyxfunc.C (getStatus): also set flag disabled if it is a unknown action. +2003-10-16 André Pönitz + + * lyxrow.[Ch]: + * paragraph.h: + * rowpainter.C: + * text.C: + * text2.C: + * text3.C: speed up by storing y positions per paragraph plus per-row + offset instead of having a 'full' y position in the row. + 2003-10-15 André Pönitz * iterators.[Ch]: diff --git a/src/lyxrow.C b/src/lyxrow.C index 20a73b5c2d..8ae4715e65 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -23,14 +23,14 @@ using lyx::pos_type; Row::Row() - : pos_(0), end_(0), fill_(0), height_(0), width_(0), y_(0), + : pos_(0), end_(0), fill_(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) {} Row::Row(pos_type pos) - : pos_(pos), end_(0), fill_(0), height_(0), width_(0), y_(0), + : pos_(pos), end_(0), fill_(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) {} @@ -181,6 +181,6 @@ void Row::dump(const char * s) const << " fill: " << fill_ << " ascent_of_text: " << ascent_of_text_ << " top_of_text: " << top_of_text_ - << " y: " << y_ << std::endl; + << " y_offset: " << y_offset_ << std::endl; } diff --git a/src/lyxrow.h b/src/lyxrow.h index 2b21b3265c..585b46cb8b 100644 --- a/src/lyxrow.h +++ b/src/lyxrow.h @@ -59,9 +59,9 @@ public: /// return true if this row is the start of a paragraph bool isParStart() const; /// return the cached y position - unsigned int y() const { return y_; } + unsigned int y_offset() const { return y_offset_; } /// cache the y position - void y(unsigned int newy) { y_ = newy; } + void y_offset(unsigned int newy) { y_offset_ = newy; } /// float x() const; /// @@ -93,7 +93,7 @@ private: /// unsigned int width_; /// cached y position - unsigned int y_; + unsigned int y_offset_; /// ascent from baseline including prelude space unsigned short ascent_of_text_; /// the top of the real text in the row diff --git a/src/paragraph.C b/src/paragraph.C index c949662f71..351c8e4434 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -52,7 +52,7 @@ using std::ostringstream; Paragraph::Paragraph() - : y(0), pimpl_(new Paragraph::Pimpl(this)) + : y(0), height(0), pimpl_(new Paragraph::Pimpl(this)) { itemdepth = 0; params().clear(); @@ -60,7 +60,7 @@ Paragraph::Paragraph() Paragraph::Paragraph(Paragraph const & lp) - : y(0), text_(lp.text_), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this)) + : y(0), height(0), text_(lp.text_), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this)) { itemdepth = 0; // this is because of the dummy layout of the paragraphs that diff --git a/src/paragraph.h b/src/paragraph.h index 839cc54da4..deeab42ff3 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -302,6 +302,8 @@ public: mutable RowList rows; /// last draw y position (baseline of top row) int y; + /// + int height; private: /// diff --git a/src/rowpainter.C b/src/rowpainter.C index ac1fadd6a0..961954ae5f 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -1089,7 +1089,7 @@ int paintText(BufferView & bv) int const topy = bv.top_y(); ParagraphList::iterator pit; RowList::iterator rit = bv.text->getRowNearY(topy, pit); - int y = rit->y() - topy; + int const y = pit->y + rit->y_offset() - topy; return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0); } diff --git a/src/text.C b/src/text.C index 5114548c38..2aa7c803af 100644 --- a/src/text.C +++ b/src/text.C @@ -93,12 +93,8 @@ void LyXText::updateRowPositions() ParagraphList::iterator pit = ownerParagraphs().begin(); ParagraphList::iterator end = ownerParagraphs().end(); for (height = 0; pit != end; ++pit) { - RowList::iterator rit = pit->rows.begin(); - RowList::iterator rend = pit->rows.end(); - for ( ; rit != rend ; ++rit) { - rit->y(height); - height += rit->height(); - } + pit->y = height; + height += pit->height; } } @@ -2021,8 +2017,8 @@ RowList::iterator LyXText::cursorIRow() const } -RowList::iterator LyXText::getRowNearY(int y, - ParagraphList::iterator & pit) const +RowList::iterator LyXText::getRowNearY(int y, ParagraphList::iterator & pit) + const { //lyxerr << "getRowNearY: y " << y << endl; @@ -2031,7 +2027,7 @@ RowList::iterator LyXText::getRowNearY(int y, RowList::iterator rit = lastRow(); RowList::iterator rbegin = firstRow(); - while (rit != rbegin && static_cast(rit->y()) > y) + while (rit != rbegin && pit->y + rit->y_offset() > y) previousRow(pit, rit); return rit; diff --git a/src/text2.C b/src/text2.C index a9a9bc0024..2c72d43b73 100644 --- a/src/text2.C +++ b/src/text2.C @@ -575,6 +575,7 @@ int LyXText::redoParagraphInternal(ParagraphList::iterator pit) int par_width = 0; // set height and fill and width of rows int const ww = workWidth(); + pit->height = 0; for (rit = pit->rows.begin(); rit != end; ++rit) { int const f = fill(pit, rit, ww); int const w = ww - f; @@ -583,8 +584,10 @@ int LyXText::redoParagraphInternal(ParagraphList::iterator pit) rit->width(w); prepareToPrint(pit, rit); setHeightOfRow(pit, rit); - height += rit->height(); + rit->y_offset(pit->height); + pit->height += rit->height(); } + height += pit->height; //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n"; return par_width; @@ -1404,7 +1407,7 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par, ParagraphList::iterator pit = getPar(par); RowList::iterator row = getRow(pit, pos); - int y = row->y(); + int y = pit->y + row->y_offset(); // y is now the beginning of the cursor row y += row->baseline(); @@ -1661,7 +1664,7 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y) // Get the row first. ParagraphList::iterator pit; RowList::iterator rit = getRowNearY(y, pit); - y = rit->y(); + y = pit->y + rit->y_offset(); bool bound = false; pos_type const column = getColumnNearX(pit, rit, x, bound); diff --git a/src/text3.C b/src/text3.C index 200d8c949f..5559d99abf 100644 --- a/src/text3.C +++ b/src/text3.C @@ -313,7 +313,8 @@ void LyXText::cursorNext() } ParagraphList::iterator dummypit; - y = getRowNearY(y, dummypit)->y(); + RowList::iterator rr = getRowNearY(y, dummypit); + y = dummypit->y + rr->y_offset(); setCursorFromCoordinates(cursor.x_fix(), y); // + bv->workHeight());