I'd like to get insettext/insettabular on par with the rest of insets/* which I believe is in comparatively good shape nowadays.
The attached patch removes InsetText::InnerCache and tells all users of it that there is not anything valid in the cache (i.e. assume find(...) == end() and remove all other branches) I've played around with it quite a bit, even with 'large' docs as the UserGuide and have not found any loss in speed whatsoever. So it looks like there are 136 lines that simply can go for starters... Ok to commit? Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)
Index: insets/insettext.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v retrieving revision 1.405 diff -u -p -r1.405 insettext.C --- insets/insettext.C 3 Jun 2003 15:10:12 -0000 1.405 +++ insets/insettext.C 5 Jun 2003 06:11:05 -0000 @@ -79,8 +79,8 @@ using lyx::textclass_type; void InsetText::saveLyXTextState(LyXText * t) const { // check if my paragraphs are still valid - ParagraphList::iterator it = const_cast<ParagraphList&>(paragraphs).begin(); - ParagraphList::iterator end = const_cast<ParagraphList&>(paragraphs).end(); + ParagraphList::const_iterator it = paragraphs.begin(); + ParagraphList::const_iterator end = paragraphs.end(); for (; it != end; ++it) { if (it == t->cursor.par()) break; @@ -106,11 +106,11 @@ void InsetText::saveLyXTextState(LyXText void InsetText::restoreLyXTextState(LyXText * t) const { - if (sstate.lpar == const_cast<ParagraphList&>(paragraphs).end()) + if (sstate.lpar == paragraphs.end()) return; t->selection.set(true); - /* at this point just to avoid the DEPM when setting the cursor */ + // at this point just to avoid the DEPM when setting the cursor t->selection.mark(sstate.mark_set); if (sstate.selection) { t->setCursor(sstate.selstartpar, sstate.selstartpos, @@ -128,13 +128,6 @@ void InsetText::restoreLyXTextState(LyXT } -InsetText::InnerCache::InnerCache(boost::shared_ptr<LyXText> t) -{ - text = t; - remove = false; -} - - InsetText::InsetText(BufferParams const & bp) : UpdatableInset(), lt(0), in_update(false), do_resize(0), do_reinit(false) @@ -2093,41 +2086,6 @@ LyXText * InsetText::getLyXText(BufferVi BufferView * bv = const_cast<BufferView *>(lbv); cached_bview = bv; - Cache::iterator it = cache.find(bv); - - if (it != cache.end()) { - if (do_reinit) { - reinitLyXText(); - } else if (do_resize) { - resizeLyXText(do_resize); - } else { - if (lt || !it->second.remove) { - lyx::Assert(it->second.text.get()); - cached_text = it->second.text; - if (recursive && the_locking_inset) { - return the_locking_inset->getLyXText(bv, true); - } - return cached_text.get(); - } else if (it->second.remove) { - if (locked) { - saveLyXTextState(it->second.text.get()); - } else { - sstate.lpar = const_cast<ParagraphList&>(paragraphs).end(); - } - } - // - // when we have to reinit the existing LyXText! - // - it->second.text->init(bv); - restoreLyXTextState(it->second.text.get()); - it->second.remove = false; - } - cached_text = it->second.text; - if (the_locking_inset && recursive) { - return the_locking_inset->getLyXText(bv); - } - return cached_text.get(); - } /// // we are here only if we don't have a BufferView * in the cache!!! /// @@ -2135,38 +2093,19 @@ LyXText * InsetText::getLyXText(BufferVi cached_text->init(bv); restoreLyXTextState(cached_text.get()); - cache.insert(make_pair(bv, cached_text)); - - if (the_locking_inset && recursive) { + if (the_locking_inset && recursive) return the_locking_inset->getLyXText(bv); - } return cached_text.get(); } -void InsetText::deleteLyXText(BufferView * bv, bool recursive) const +void InsetText::deleteLyXText(BufferView *, bool) const { cached_bview = 0; - - Cache::iterator it = cache.find(bv); - - if (it == cache.end()) { - return; - } - - lyx::Assert(it->second.text.get()); - - it->second.remove = true; - if (recursive) { - /// then remove all LyXText in text-insets - for_each(const_cast<ParagraphList&>(paragraphs).begin(), - const_cast<ParagraphList&>(paragraphs).end(), - boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv)); - } } -void InsetText::resizeLyXText(BufferView * bv, bool force) const +void InsetText::resizeLyXText(BufferView * bv, bool) const { if (lt) { // we cannot resize this because we are in use! @@ -2184,38 +2123,6 @@ void InsetText::resizeLyXText(BufferView restoreLyXTextState(t); return; } - // one endless line, resize normally not necessary - if (!force && getMaxWidth(bv, this) < 0) - return; - - Cache::iterator it = cache.find(bv); - if (it == cache.end()) { - return; - } - lyx::Assert(it->second.text.get()); - - LyXText * t = it->second.text.get(); - saveLyXTextState(t); - - for_each(const_cast<ParagraphList&>(paragraphs).begin(), - const_cast<ParagraphList&>(paragraphs).end(), - boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv)); - - t->init(bv, true); - restoreLyXTextState(t); - if (the_locking_inset) { - inset_x = cix(bv) - top_x + drawTextXOffset; - inset_y = ciy(bv) + drawTextYOffset; - } - - t->top_y(bv->screen().topCursorVisible(t->cursor, t->top_y())); - if (!owner()) { - const_cast<InsetText*>(this)->updateLocal(bv, FULL, false); - // this will scroll the screen such that the cursor becomes visible - bv->updateScrollbar(); - } else { - need_update |= FULL; - } } @@ -2229,33 +2136,6 @@ void InsetText::reinitLyXText() const } do_reinit = false; do_resize = 0; - for (Cache::iterator it = cache.begin(); it != cache.end(); ++it) { - lyx::Assert(it->second.text.get()); - - LyXText * t = it->second.text.get(); - BufferView * bv = it->first; - - saveLyXTextState(t); - - for_each(const_cast<ParagraphList&>(paragraphs).begin(), - const_cast<ParagraphList&>(paragraphs).end(), - boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv)); - - t->init(bv, true); - restoreLyXTextState(t); - if (the_locking_inset) { - inset_x = cix(bv) - top_x + drawTextXOffset; - inset_y = ciy(bv) + drawTextYOffset; - } - t->top_y(bv->screen().topCursorVisible(t->cursor, t->top_y())); - if (!owner()) { - const_cast<InsetText*>(this)->updateLocal(bv, FULL, false); - // this will scroll the screen such that the cursor becomes visible - bv->updateScrollbar(); - } else { - need_update = FULL; - } - } } Index: insets/insettext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v retrieving revision 1.167 diff -u -p -r1.167 insettext.h --- insets/insettext.h 3 Jun 2003 15:10:13 -0000 1.167 +++ insets/insettext.h 5 Jun 2003 06:11:05 -0000 @@ -23,7 +23,6 @@ #include "support/types.h" #include <boost/shared_ptr.hpp> -#include <map> class Painter; class BufferView; @@ -271,19 +270,6 @@ private: void lfunMouseMotion(FuncRequest const &); /// - struct InnerCache { - /// - InnerCache(boost::shared_ptr<LyXText>); - /// - boost::shared_ptr<LyXText> text; - /// - bool remove; - }; - /// - typedef std::map<BufferView *, InnerCache> Cache; - /// - typedef Cache::value_type value_type; - /// RESULT moveRight(BufferView *, bool activate_inset = true, bool selecting = false); @@ -367,8 +353,6 @@ private: UpdatableInset * the_locking_inset; /// mutable ParagraphList::iterator old_par; - /// The cache. - mutable Cache cache; /// mutable int last_drawn_width; ///