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
This commit is contained in:
Jürgen Vigna 2001-07-02 15:29:23 +00:00
parent fff924cc29
commit 6687595f9c
3 changed files with 27 additions and 6 deletions

View File

@ -1,3 +1,11 @@
2001-07-02 Juergen Vigna <jug@sad.it>
* 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 <Jean-Marc.Lasgouttes@inria.fr> 2001-06-29 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* insettabular.C (clone): do not copy the LyXTabular twice * insettabular.C (clone): do not copy the LyXTabular twice

View File

@ -111,6 +111,7 @@ void InsetText::init(InsetText const * ins)
old_par = 0; old_par = 0;
last_drawn_width = -1; last_drawn_width = -1;
frame_is_visible = false; frame_is_visible = false;
cached_bview = 0;
} }
@ -118,6 +119,7 @@ InsetText::~InsetText()
{ {
// delete all instances of LyXText before deleting the paragraps used // delete all instances of LyXText before deleting the paragraps used
// by it. // by it.
cached_bview = 0;
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) { for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
delete (*cit).second; delete (*cit).second;
(*cit).second = 0; (*cit).second = 0;
@ -135,6 +137,7 @@ void InsetText::clear()
{ {
// delete all instances of LyXText before deleting the paragraps used // delete all instances of LyXText before deleting the paragraps used
// by it. // by it.
cached_bview = 0;
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) { for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
delete (*cit).second; delete (*cit).second;
(*cit).second = 0; (*cit).second = 0;
@ -1498,6 +1501,7 @@ void InsetText::setParagraphData(Paragraph * p)
{ {
// delete all instances of LyXText before deleting the paragraps used // delete all instances of LyXText before deleting the paragraps used
// by it. // by it.
cached_bview = 0;
for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){ for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){
delete (*cit).second; delete (*cit).second;
(*cit).second = 0; (*cit).second = 0;
@ -1613,28 +1617,34 @@ Row * InsetText::crow(BufferView * bv) const
LyXText * InsetText::getLyXText(BufferView const * lbv, LyXText * InsetText::getLyXText(BufferView const * lbv,
bool const recursive) const bool const recursive) const
{ {
if (!recursive && cached_bview && (cached_bview == lbv))
return cached_text;
// Super UGLY! (Lgb) // Super UGLY! (Lgb)
BufferView * bv = const_cast<BufferView *>(lbv); BufferView * bv = const_cast<BufferView *>(lbv);
cached_bview = bv;
if ((cache.find(bv) != cache.end()) && cache[bv]) { if ((cache.find(bv) != cache.end()) && cache[bv]) {
cached_text = cache[bv];
if (recursive && the_locking_inset) if (recursive && the_locking_inset)
return the_locking_inset->getLyXText(bv); return the_locking_inset->getLyXText(bv);
return cache[bv]; return cached_text;
} }
LyXText * lt = new LyXText(const_cast<InsetText *>(this)); cached_text = new LyXText(const_cast<InsetText *>(this));
lt->init(bv); cached_text->init(bv);
cache[bv] = lt; cache[bv] = cached_text;
if (the_locking_inset) { 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) if (recursive)
return the_locking_inset->getLyXText(bv); return the_locking_inset->getLyXText(bv);
} }
return lt; return cached_text;
} }
void InsetText::deleteLyXText(BufferView * bv, bool recursive) const void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
{ {
cached_bview = 0;
if ((cache.find(bv) == cache.end()) || !cache[bv]) if ((cache.find(bv) == cache.end()) || !cache[bv])
return; return;
delete cache[bv]; delete cache[bv];

View File

@ -322,5 +322,8 @@ private:
mutable int last_drawn_width; mutable int last_drawn_width;
/// ///
mutable bool frame_is_visible; mutable bool frame_is_visible;
///
mutable BufferView * cached_bview;
mutable LyXText * cached_text;
}; };
#endif #endif