On 29-Jun-2001 Jean-Marc Lasgouttes wrote:

> Let's say it is showing in the few first lines of gprof output,
> whatever that means. A few percents, which is huge for such a mundane
> task, IMO.

Would you please test the following patch? It inserts a "secure" caching
mechanism into insettext without the need to change a lot of code. Do you
see differences in execute time?

        Jürgen

--
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._
Dr. Jürgen Vigna        E-Mail:  [EMAIL PROTECTED]
Italienallee 13/N       Tel/Fax: +39-0471-450260 / +39-0471-450253
I-39100 Bozen           Web:     http://www.sad.it/~jug
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._

Everyone is entitled to my opinion.

Index: po/POTFILES.in
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/po/POTFILES.in,v
retrieving revision 1.186
diff -u -p -r1.186 POTFILES.in
--- po/POTFILES.in      2001/06/27 14:10:22     1.186
+++ po/POTFILES.in      2001/06/29 11:03:26
@@ -9,7 +9,6 @@ src/converter.C
 src/CutAndPaste.C
 src/debug.C
 src/exporter.C
-src/ext_l10n.h
 src/figure_form.C
 src/figureForm.C
 src/FontLoader.C
Index: src/insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.157
diff -u -p -r1.157 insettext.C
--- src/insets/insettext.C      2001/06/29 06:30:52     1.157
+++ src/insets/insettext.C      2001/06/29 11:03:27
@@ -111,6 +111,7 @@ void InsetText::init(InsetText const * i
        old_par = 0;
        last_drawn_width = -1;
        frame_is_visible = false;
+       cached_bview = 0;
 }
 
 
@@ -1594,28 +1595,34 @@ Row * InsetText::crow(BufferView * bv) c
 LyXText * InsetText::getLyXText(BufferView const * lbv,
                                bool const recursive) const
 {
+       if (!recursive && cached_bview && (cached_bview == lbv))
+               return cached_text;
+
        // Super UGLY! (Lgb)
        BufferView * bv = const_cast<BufferView *>(lbv);
        
+       cached_bview = bv;
        if ((cache.find(bv) != cache.end()) && cache[bv]) {
+               cached_text = cache[bv];
                if (recursive && the_locking_inset)
                        return the_locking_inset->getLyXText(bv);
-               return cache[bv];
+               return cached_text;
        }
-       LyXText * lt = new LyXText(const_cast<InsetText *>(this));
-       lt->init(bv);
-       cache[bv] = lt;
+       cached_text = new LyXText(const_cast<InsetText *>(this));
+       cached_text->init(bv);
+       cache[bv] = cached_text;
        if (the_locking_inset) {
-               lt->setCursor(bv, inset_par, inset_pos, true, inset_boundary);
+               cached_text->setCursor(bv, inset_par, inset_pos, true, inset_boundary);
                if (recursive)
                        return the_locking_inset->getLyXText(bv);
        }
-       return lt;
+       return cached_text;
 }
 
 
 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
 {
+       cached_bview = 0;
        if ((cache.find(bv) == cache.end()) || !cache[bv])
                return;
        delete cache[bv];
Index: src/insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.74
diff -u -p -r1.74 insettext.h
--- src/insets/insettext.h      2001/06/28 10:25:20     1.74
+++ src/insets/insettext.h      2001/06/29 11:03:27
@@ -327,5 +327,8 @@ private:
        mutable int last_drawn_width;
        ///
        mutable bool frame_is_visible;
+       ///
+       mutable BufferView * cached_bview;
+       mutable LyXText * cached_text;
 };
 #endif

Reply via email to