]> git.lyx.org Git - features.git/commitdiff
make updateRowPositions() a bit faster.
authorAndré Pönitz <poenitz@gmx.net>
Thu, 16 Oct 2003 16:19:56 +0000 (16:19 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 16 Oct 2003 16:19:56 +0000 (16:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7926 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/lyxrow.C
src/lyxrow.h
src/paragraph.C
src/paragraph.h
src/rowpainter.C
src/text.C
src/text2.C
src/text3.C

index 16f26dc97c4f837b8e86541dd8b89c0a21b5d153..33e73fbd90798211ee686493962358792c8cb973 100644 (file)
@@ -3,6 +3,16 @@
        * lyxfunc.C (getStatus): also set flag disabled if it is a unknown
        action.
 
+2003-10-16  André Pönitz  <poenitz@gmx.net>
+
+       * 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  <poenitz@gmx.net>
 
        * iterators.[Ch]:
index 20a73b5c2de09d5a18fd3edee73040b5c79c90b6..8ae4715e650e0f6aadf5a74126a3382ed6f95471 100644 (file)
@@ -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;
 }
 
index 2b21b3265c6f3e7c6b2bbbc606a12ea22f9f942e..585b46cb8b6479dc5459954d20fd8ab4acc00c4d 100644 (file)
@@ -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
index c949662f7154019fb4fadc2b88d89a44921403c1..351c8e4434abe4ee3ccd45459354448ebb3aac6b 100644 (file)
@@ -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
index 839cc54da48dc80975086a0782259e733a11a10f..deeab42ff3012635b810e21ac8050596b1e86644 100644 (file)
@@ -302,6 +302,8 @@ public:
        mutable RowList rows;
        /// last draw y position (baseline of top row)
        int y;
+       ///
+       int height;
 
 private:
        ///
index ac1fadd6a0416ad30f1689104b6f3b6c391d9151..961954ae5f10c186b52f1a2ab08a2b34e95bad35 100644 (file)
@@ -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);
 }
 
index 5114548c38103174da6329e3e632ab8de858c01d..2aa7c803affd7fc860ff6dff0e99a668654c9df7 100644 (file)
@@ -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<int>(rit->y()) > y)
+       while (rit != rbegin && pit->y + rit->y_offset() > y)
                previousRow(pit, rit);
 
        return rit;
index a9a9bc00243711d37ed919722e28e20734f80399..2c72d43b7394acd98317be790722920f006f2cb9 100644 (file)
@@ -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);
index 200d8c949f353f93c631a14d0ce35600cf3fbef1..5559d99abf2344f8b709131a07f5a8ac482d2862 100644 (file)
@@ -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());