From e5c1dd967be41ebdf8920edfcae427e0cc0aee86 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sun, 15 Aug 2004 16:52:44 +0000 Subject: [PATCH] some profiler work, a few cleanups git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8942 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 11 +++++++++ src/insets/ChangeLog | 2 ++ src/insets/insettabular.C | 12 +++++----- src/paragraph.C | 8 +++---- src/rowpainter.C | 11 ++++----- src/text.C | 14 ++++++------ src/text2.C | 47 ++++++++++++++++++++------------------- 7 files changed, 60 insertions(+), 45 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 38b193773b..edca42ca4f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2004-08-15 Jean-Marc Lasgouttes + + * text2.C (setCounter): reduce number of calls to pars_[pit] + + * text.C (singleWidth): add an assert, fix a test + + * rowpainter.C (paintText): reduce number of calls to singleWidth + + * paragraph.C (isHfill): + (isNewline): ws only + 2004-08-14 André Pönitz * text.C: diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 81ca55cf31..e733aab7e2 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,5 +1,7 @@ 2004-08-15 Jean-Marc Lasgouttes + * insettabular.C (draw): whitespace + * insetnewline.C (draw): use PainterInfo::ltr_pos instead of ownerPar. 2004-08-14 André Pönitz diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 541d38a563..98d39ea7fb 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -270,12 +270,11 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const for (int i = 0; i < tabular.rows(); ++i) { int nx = x; idx = tabular.getCellNumber(i, 0); - if (y + tabular.getDescentOfRow(i) <= 0 && - y - tabular.getAscentOfRow(i) < pi.pain.paperHeight()) - { - y += tabular.getDescentOfRow(i) + - tabular.getAscentOfRow(i + 1) + - tabular.getAdditionalHeight(i + 1); + if (y + tabular.getDescentOfRow(i) <= 0 + && y - tabular.getAscentOfRow(i) < pi.pain.paperHeight()) { + y += tabular.getDescentOfRow(i) + + tabular.getAscentOfRow(i + 1) + + tabular.getAdditionalHeight(i + 1); continue; } for (int j = 0; j < tabular.columns(); ++j) { @@ -965,6 +964,7 @@ void InsetTabular::getCursorPos(LCursor const & cur, int & x, int & y) const InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const { + lyxerr << "# InsetTabular::setPos() x=" << x << " y=" << y << endl; int idx_min = 0; int dist_min = 1000000; for (idx_type i = 0; i < nargs(); ++i) { diff --git a/src/paragraph.C b/src/paragraph.C index 1dd00d4dee..b139c85fee 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1481,15 +1481,15 @@ bool IsInsetChar(char c) bool Paragraph::isHfill(pos_type pos) const { - return - isInset(pos) && getInset(pos)->lyxCode() == InsetBase::HFILL_CODE; + return isInset(pos) + && getInset(pos)->lyxCode() == InsetBase::HFILL_CODE; } bool Paragraph::isNewline(pos_type pos) const { - return - isInset(pos) && getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE; + return isInset(pos) + && getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE; } diff --git a/src/rowpainter.C b/src/rowpainter.C index 7f2694101b..378ffece67 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -767,15 +767,16 @@ void RowPainter::paintText() if (x_ > bv_.workWidth()) break; - pos_type pos = text_.bidi.vis2log(vpos); + pos_type const pos = text_.bidi.vis2log(vpos); if (pos >= par_.size()) { ++vpos; continue; } - if (x_ + singleWidth(pos) < 0) { - x_ += singleWidth(pos); + const int width_pos = singleWidth(pos); + if (x_ + width_pos < 0) { + x_ += width_pos; ++vpos; continue; } @@ -803,7 +804,7 @@ void RowPainter::paintText() int const lwidth = font_metrics::width(layout->labelsep, getLabelFont()); - x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1); + x_ += label_hfill_ + lwidth - width_pos; } if (par_.isHfill(pos)) { @@ -833,7 +834,7 @@ void RowPainter::paintText() x_ += 2; ++vpos; } else if (par_.isSeparator(pos)) { - x_ += singleWidth(pos); + x_ += width_pos; if (pos >= body_pos) x_ += separator_; ++vpos; diff --git a/src/text.C b/src/text.C index 853ddfa29d..ae921143a9 100644 --- a/src/text.C +++ b/src/text.C @@ -448,15 +448,11 @@ int LyXText::singleWidth(Paragraph const & par, pos_type pos) const int LyXText::singleWidth(Paragraph const & par, pos_type pos, char c, LyXFont const & font) const { - if (pos >= par.size()) { - lyxerr << "in singleWidth(), pos: " << pos << endl; - BOOST_ASSERT(false); - return 0; - } + BOOST_ASSERT(pos < par.size()); // The most common case is handled first (Asger) if (IsPrintable(c)) { - if (!font.language()->RightToLeft()) { + if (font.language()->RightToLeft()) { if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 || lyxrc.font_norm_type == LyXRC::ISO_10646_1) && font.language()->lang() == "arabic") { @@ -465,7 +461,7 @@ int LyXText::singleWidth(Paragraph const & par, else c = par.transformChar(c, pos); } else if (font.language()->lang() == "hebrew" && - Encodings::IsComposeChar_hebrew(c)) + Encodings::IsComposeChar_hebrew(c)) return 0; } return font_metrics::width(c, font); @@ -2121,5 +2117,9 @@ int LyXText::dist(int x, int y) const else if (y > yo_ + descent()) yy = y - yo_ - descent(); + lyxerr << " xo_=" << xo_ << " yo_=" << yo_ + << " width_=" << width_ << " ascent=" << ascent() + << " descent=" << descent() + << " dist=" << xx+yy <margintype == MARGIN_MANUAL) { - if (pars_[pit].params().labelWidthString().empty()) - pars_[pit].setLabelWidthString(layout->labelstring()); + if (par.params().labelWidthString().empty()) + par.setLabelWidthString(layout->labelstring()); } else { - pars_[pit].setLabelWidthString(string()); + par.setLabelWidthString(string()); } // is it a layout that has an automatic label? @@ -746,16 +747,16 @@ void LyXText::setCounter(Buffer const & buf, par_type pit) BufferParams const & bufparams = buf.params(); LyXTextClass const & textclass = bufparams.getLyXTextClass(); counters.step(layout->counter); - string label = expandLabel(textclass, layout, pars_[pit].params().appendix()); - pars_[pit].params().labelString(label); + string label = expandLabel(textclass, layout, par.params().appendix()); + par.params().labelString(label); } else if (layout->labeltype == LABEL_ITEMIZE) { // At some point of time we should do something more // clever here, like: - // pars_[pit].params().labelString( - // bufparams.user_defined_bullet(pars_[pit].itemdepth).getText()); + // par.params().labelString( + // bufparams.user_defined_bullet(par.itemdepth).getText()); // for now, use a simple hardcoded label string itemlabel; - switch (pars_[pit].itemdepth) { + switch (par.itemdepth) { case 0: itemlabel = "*"; break; @@ -770,7 +771,7 @@ void LyXText::setCounter(Buffer const & buf, par_type pit) break; } - pars_[pit].params().labelString(itemlabel); + par.params().labelString(itemlabel); } else if (layout->labeltype == LABEL_ENUMERATE) { // Maybe we have to reset the enumeration counter. resetEnumCounterIfNeeded(pars_, pit, first_pit, counters); @@ -780,7 +781,7 @@ void LyXText::setCounter(Buffer const & buf, par_type pit) // (Lgb) string enumcounter = "enum"; - switch (pars_[pit].itemdepth) { + switch (par.itemdepth) { case 2: enumcounter += 'i'; case 1: @@ -798,13 +799,13 @@ void LyXText::setCounter(Buffer const & buf, par_type pit) counters.step(enumcounter); - pars_[pit].params().labelString(counters.enumLabel(enumcounter)); + par.params().labelString(counters.enumLabel(enumcounter)); } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 counters.step("bibitem"); int number = counters.value("bibitem"); - if (pars_[pit].bibitem()) { - pars_[pit].bibitem()->setCounter(number); - pars_[pit].params().labelString(layout->labelstring()); + if (par.bibitem()) { + par.bibitem()->setCounter(number); + par.params().labelString(layout->labelstring()); } // In biblio should't be following counters but... } else { @@ -853,7 +854,7 @@ void LyXText::setCounter(Buffer const & buf, par_type pit) s = _("Senseless: "); } } - pars_[pit].params().labelString(s); + par.params().labelString(s); } } -- 2.39.5