Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes: >>>>>> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: > | Lars> I think this is a better algorithm for font lookup. (at least | Lars> gprof tells me so) > | This is probably true, since there are very few font changes in a | typical paragraph. What are the getFontSettings numbers down to?
Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls us/call us/call name 7.52 0.31 0.31 2043074 0.15 0.29 LyXTextClass::operator[](std::string const&) const 6.80 0.59 0.28 1397195 0.20 1.31 LyXText::getFont(Buffer const*, Paragraph*, int) const 6.31 0.85 0.26 1401073 0.19 0.23 Paragraph::getFontSettings(BufferParams const&, int) const | I've been wanting to work on getFontSetting after 1.2.0, so I would | like to see whether this very simple approach is enough. I have done the same change to other functions that used matchFT and lowerbound.
Index: paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.196 diff -u -p -r1.196 paragraph.C --- paragraph.C 7 Mar 2002 10:51:45 -0000 1.196 +++ paragraph.C 13 Mar 2002 09:23:46 -0000 @@ -581,11 +581,21 @@ LyXFont const Paragraph::getFontSettings pos_type pos) const { lyx::Assert(pos <= size()); - + +#if 0 Pimpl::FontTable search_font(pos, LyXFont()); Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(), pimpl_->fontlist.end(), search_font, Pimpl::matchFT()); +#else + Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin(); + Pimpl::FontList::const_iterator end = pimpl_->fontlist.end(); + for (; cit != end; ++cit) { + if (cit->pos() > pos) + break; + } +#endif + LyXFont retfont; if (cit != pimpl_->fontlist.end()) { retfont = cit->font(); @@ -680,20 +690,36 @@ Paragraph::highestFontInRange(pos_type s return def_size; LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY; +#if 0 Pimpl::FontTable end_search(endpos, LyXFont()); Pimpl::FontList::const_iterator end_it = lower_bound(pimpl_->fontlist.begin(), pimpl_->fontlist.end(), end_search, Pimpl::matchFT()); +#else + Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin(); + Pimpl::FontList::const_iterator end = pimpl_->fontlist.end(); + for (; end_it != end; ++end_it) { + if (end_it->pos() > endpos) + break; + } +#endif if (end_it != pimpl_->fontlist.end()) ++end_it; +#if 0 Pimpl::FontTable start_search(startpos, LyXFont()); Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(), pimpl_->fontlist.end(), start_search, Pimpl::matchFT()); - +#else + Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin(); + for (; cit != end; ++cit) { + if (cit->pos() > startpos) + break; + } +#endif for (; cit != end_it; ++cit) { LyXFont::FONT_SIZE size = cit->font().size(); if (size == LyXFont::INHERIT_SIZE) @@ -757,13 +783,23 @@ void Paragraph::setFont(pos_type pos, Ly // in a new kernel. (Asger) // Next search font table +#if 0 Pimpl::FontTable search_font(pos, LyXFont()); Pimpl::FontList::iterator it = lower_bound(pimpl_->fontlist.begin(), pimpl_->fontlist.end(), search_font, Pimpl::matchFT()); unsigned int i = it - pimpl_->fontlist.begin(); bool notfound = it == pimpl_->fontlist.end(); - +#else + Pimpl::FontList::iterator it = pimpl_->fontlist.begin(); + Pimpl::FontList::iterator endit = pimpl_->fontlist.end(); + for (; it != endit; ++it) { + if (it->pos() > pos) + break; + } + unsigned int i = std::distance(pimpl_->fontlist.begin(), it); + bool notfound = (it == endit); +#endif if (!notfound && pimpl_->fontlist[i].font() == font) return;
-- Lgb