I think this is a better algorithm for font lookup.
(at least gprof tells me so)

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 12 Mar 2002 22:33:01 -0000
@@ -581,7 +581,8 @@ 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(),
@@ -599,6 +600,34 @@ LyXFont const Paragraph::getFontSettings
 #endif

        return retfont;
+#else
+       //Pimpl::FontTable search_font(pos, LyXFont());
+       //lyxerr << "Fontlist size = " << pimpl_->fontlist.size() << endl;
+
+       //Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(),
+       //                                         pimpl_->fontlist.end(),
+       //                                         search_font, Pimpl::matchFT());
+       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;
+       }
+
+       LyXFont retfont;
+       if (cit != pimpl_->fontlist.end()) {
+               retfont = cit->font();
+       } else if (pos == size() && size()) {
+               retfont = getFontSettings(bparams, pos - 1);
+       } else
+               retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
+#ifdef INHERIT_LANGUAGE
+       if (retfont.language() == inherit_language)
+               retfont.setLanguage(bparams.language);
+#endif
+
+       return retfont;
+#endif
 }


-- 
        Lgb

Reply via email to