From 6687595f9c4601444e95eddf240ee5e071bee611 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Mon, 2 Jul 2001 15:29:23 +0000 Subject: [PATCH] Introduce a local cache to the getLyXText method for repetitive calls. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2167 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/ChangeLog | 8 ++++++++ src/insets/insettext.C | 22 ++++++++++++++++------ src/insets/insettext.h | 3 +++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index da16752172..4c89234b22 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ +2001-07-02 Juergen Vigna + + * insettext.C (getLyXText): introduce a cache in getLyXText so that + following calls are only returned the right pointer without the over + head to search in the map. + (various funcs): reset the cached_bview variable as this signs that + the cache is not valid anymore. + 2001-06-29 Jean-Marc Lasgouttes * insettabular.C (clone): do not copy the LyXTabular twice diff --git a/src/insets/insettext.C b/src/insets/insettext.C index a86af9914e..2fc280d971 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -111,6 +111,7 @@ void InsetText::init(InsetText const * ins) old_par = 0; last_drawn_width = -1; frame_is_visible = false; + cached_bview = 0; } @@ -118,6 +119,7 @@ InsetText::~InsetText() { // delete all instances of LyXText before deleting the paragraps used // by it. + cached_bview = 0; for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) { delete (*cit).second; (*cit).second = 0; @@ -135,6 +137,7 @@ void InsetText::clear() { // delete all instances of LyXText before deleting the paragraps used // by it. + cached_bview = 0; for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) { delete (*cit).second; (*cit).second = 0; @@ -1498,6 +1501,7 @@ void InsetText::setParagraphData(Paragraph * p) { // delete all instances of LyXText before deleting the paragraps used // by it. + cached_bview = 0; for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){ delete (*cit).second; (*cit).second = 0; @@ -1613,28 +1617,34 @@ Row * InsetText::crow(BufferView * bv) const 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(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(this)); - lt->init(bv); - cache[bv] = lt; + cached_text = new LyXText(const_cast(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]; diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 22e55d640a..a11eee2515 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -322,5 +322,8 @@ private: mutable int last_drawn_width; /// mutable bool frame_is_visible; + /// + mutable BufferView * cached_bview; + mutable LyXText * cached_text; }; #endif -- 2.39.2