Attached the IMHO "current best" version of this patch, which was held
up by a discussion about the best way to find the pit value of a given
paragraph (loop, linear computation for <vector>, or some std::find
thing). This proposal doesn't assume <vector>.

I did a bit of profiling on this. The file (test 1) is found at

www.hut.fi/~mvermeer/p.txt

Test file (1) was created by typing into the end of the User Guide.
Total time 107 seconds. Couple of paragraphs typed.

Test file (2) was created by typing into LyX at the start of the User guide
for some  seconds, filling half a screen. There was no feeling of
slowness compared to pre-patch. Total time was 120 s.

Test file (3) was typing a screenful into an empty document. Total time
41 s.

Result:

Each sample counts as 0.01 seconds.
   %   cumulative   self              self     total           
   time   seconds   seconds    calls  ms/call  ms/call  name    

Test 1 (End User Guide):
   0.09     77.58     0.10    19905     0.01     0.01 
LyXText::getFont(Paragraph const&, int) const

Test 2 (Start User Guide):
   0.10     87.18     0.12    37263     0.00     0.00   
LyXText::getFont(Paragraph const&, int) const

Test 3 (Empty Doc):
   0.40     12.48     0.17    29358     0.01     0.01   
LyXText::getFont(Paragraph const&, int) const

So it seems that even with the patch, no more than fractions of seconds
are spent in LyXText::getFont. I think we can live with that. And most
importantly: even at the end of the user guide, with lots of paragraphs 
in the document above it, we see no slowing down.

Is it OK to check this in?

- Martin

Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.636
diff -u -p -r1.636 text2.C
--- text2.C     6 Dec 2005 14:54:23 -0000       1.636
+++ text2.C     6 Jan 2006 17:06:36 -0000
@@ -191,6 +191,19 @@ LyXFont LyXText::getFont(Paragraph const
        if (!isMainText())
                applyOuterFont(font);
 
+       // Find the pit value belonging to paragraph. This will not break 
+       // even if pars_ would not be a vector anymore.
+       // Performance appears acceptable.
+       pit_type pit = pars_.size();
+       for (pit_type it = 0; it < pit; ++it)
+               if (&pars_[it] == &par) {
+                       pit = it;
+                       break;
+               }
+       // Realize against environment font information
+       if (pit < pars_.size())
+               font.realize(outerFont(pit, pars_));
+
        // Realize with the fonts of lesser depth.
        font.realize(defaultfont_);
 

Attachment: pgpQOPwY1VthU.pgp
Description: PGP signature

Reply via email to