From 1684282f8a314dbab4f7fc7b38215a35336bc2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Fri, 17 Oct 2003 09:32:41 +0000 Subject: [PATCH] Get rid of the TextCache. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7928 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 46 +------------- src/ChangeLog | 17 +++++ src/Makefile.am | 2 - src/TextCache.C | 121 ------------------------------------ src/TextCache.h | 137 ----------------------------------------- src/bufferlist.C | 9 --- src/lyxfunc.C | 7 --- 7 files changed, 18 insertions(+), 321 deletions(-) delete mode 100644 src/TextCache.C delete mode 100644 src/TextCache.h diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 4e917e76f5..0b56147b05 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -41,7 +41,6 @@ #include "paragraph.h" #include "paragraph_funcs.h" #include "ParagraphParameters.h" -#include "TextCache.h" #include "undo.h" #include "vspace.h" @@ -297,14 +296,7 @@ void BufferView::Pimpl::buffer(Buffer * b) << b << ')' << endl; if (buffer_) { disconnectBuffer(); - // Put the old text into the TextCache, but - // only if the buffer is still loaded. - // Also set the owner of the test to 0 - // bv_->text->owner(0); - textcache.add(buffer_, workarea().workWidth(), bv_->text); - if (lyxerr.debugging()) - textcache.show(lyxerr, "BufferView::buffer"); - + delete bv_->text; bv_->text = 0; } @@ -339,13 +331,6 @@ void BufferView::Pimpl::buffer(Buffer * b) } else { lyxerr[Debug::INFO] << " No Buffer!" << endl; owner_->getDialogs().hideBufferDependent(); - - // Also remove all remaining text's from the testcache. - // (there should not be any!) (if there is any it is a - // bug!) - if (lyxerr.debugging()) - textcache.show(lyxerr, "buffer delete all"); - textcache.clear(); } update(); @@ -433,30 +418,11 @@ void BufferView::Pimpl::resizeCurrentBuffer() update(); } else { lyxerr << "text not available!" << endl; - // See if we have a text in TextCache that fits - // the new buffer_ with the correct width. - bv_->text = textcache.findFit(buffer_, workarea().workWidth()); - if (bv_->text) { - lyxerr << "text in cache!" << endl; - if (lyxerr.debugging()) { - lyxerr << "Found a LyXText that fits:" << endl; - textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text))); - } - // Set the owner of the newly found text - // bv_->text->owner(bv_); - if (lyxerr.debugging()) - textcache.show(lyxerr, "resizeCurrentBuffer"); - } else { lyxerr << "no text in cache!" << endl; bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs()); bv_->text->init(bv_); - } } -#warning does not help much - //bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(), - // bv_->text->ownerParagraphs().end()); - if (par != -1) { bv_->text->selection.set(true); // At this point just to avoid the Delete-Empty-Paragraph- @@ -629,16 +595,6 @@ void BufferView::Pimpl::workAreaResize() if (widthChange) { // The visible LyXView need a resize resizeCurrentBuffer(); - - // Remove all texts from the textcache - // This is not _really_ what we want to do. What - // we really want to do is to delete in textcache - // that does not have a BufferView with matching - // width, but as long as we have only one BufferView - // deleting all gives the same result. - if (lyxerr.debugging()) - textcache.show(lyxerr, "Expose delete all"); - textcache.clear(); } } diff --git a/src/ChangeLog b/src/ChangeLog index 33e73fbd90..83a24e33b5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2003-10-17 Lars Gullik Bjønnes + + * lyxfunc.C (dispatch): remove textcache stuff + + * bufferlist.C (release): remove textcache stuff + (closeAll): ditto + + * TextCache.C: delete file + * TextCache.h: delete file + + * Makefile.am (lyx_SOURCES): delete TextCache.C and TextCache.h + + * BufferView_pimpl.C (buffer): remove textcache stuff, add a + delete of the bv_->text. + (resizeCurrentBuffer): remove texcache stuff + (workAreaResize): ditto + 2003-10-16 Lars Gullik Bjønnes * lyxfunc.C (getStatus): also set flag disabled if it is a unknown diff --git a/src/Makefile.am b/src/Makefile.am index e3a938b5a2..a0ffb04762 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -102,8 +102,6 @@ lyx_SOURCES = \ ShareContainer.h \ Spacing.C \ Spacing.h \ - TextCache.C \ - TextCache.h \ Thesaurus.C \ Thesaurus.h \ ToolbarBackend.C \ diff --git a/src/TextCache.C b/src/TextCache.C deleted file mode 100644 index 4d8032554a..0000000000 --- a/src/TextCache.C +++ /dev/null @@ -1,121 +0,0 @@ -/** - * \file TextCache.C - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "TextCache.h" -#include "lyxtext.h" -#include "bufferlist.h" -#include "debug.h" - -#include - -using std::endl; -using std::find_if; -using std::for_each; -using std::make_pair; -using std::string; -using std::ostream; - -extern BufferList bufferlist; - -namespace { - -class text_fits { -public: - text_fits(Buffer * b, int p) - : buf(b), pw(p) {} - bool operator()(TextCache::value_type const & vt) const { - if (vt.first == buf && vt.second.first == pw) - return true; - return false; - } -private: - Buffer * buf; - int pw; -}; - - -class show_text { -public: - show_text(ostream & o) : os(o) {} - void operator()(TextCache::value_type const & vt) { - os << "\tBuffer: " << vt.first - << "\tWidth: " << vt.second.first << endl; - } -private: - ostream & os; -}; - - -class delete_text { -public: - void operator()(TextCache::value_type & vt) { - delete vt.second.second; - } -}; - -} // namespace anon - - -LyXText * TextCache::findFit(Buffer * b, int p) -{ - Cache::iterator it = find_if(cache.begin(), cache.end(), - text_fits(b, p)); - if (it != cache.end()) { - LyXText * tmp = it->second.second; - cache.erase(it); - return tmp; - } - return 0; -} - - -void TextCache::show(ostream & os, string const & str) -{ - os << "TextCache: " << str << endl; - for_each(cache.begin(), cache.end(), show_text(os)); -} - - -void TextCache::show(ostream & os, TextCache::value_type const & vt) -{ - show_text st(os); - st(vt); -} - - -void TextCache::add(Buffer * buf, int workwidth, LyXText * text) -{ - lyxerr[Debug::INFO] << "TextCache::add " << text; - if (bufferlist.isLoaded(buf)) { - cache[buf] = make_pair(workwidth, text); - lyxerr[Debug::INFO] << " added" << endl; - } else { - delete text; - lyxerr[Debug::INFO] << " deleted" << endl; - } -} - - -void TextCache::clear() -{ - for_each(cache.begin(), cache.end(), delete_text()); - cache.clear(); -} - - -void TextCache::removeAllWithBuffer(Buffer * buf) -{ - cache.erase(buf); -} - -// Global instance -TextCache textcache; diff --git a/src/TextCache.h b/src/TextCache.h deleted file mode 100644 index 50c6085252..0000000000 --- a/src/TextCache.h +++ /dev/null @@ -1,137 +0,0 @@ -// -*- C++ -*- -/** - * \file TextCache.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef TEXT_CACHE_H -#define TEXT_CACHE_H - -#include -#include -#include - -class Buffer; -class LyXText; - -// This is only the very first implemetation and use of the TextCache, -// operations on it needs to be put into a class or a namespace, that part -// is _NOT_ finished so don't bother to come with too many comments on it -// (unless you have some nice ideas on where/how to do it) -// -// I think we need a global TextCache that is common for all BufferViews, -// also the BufferList needs access to the TextCache. Please tell if you -// don't agree. -// -// Q. What are we caching? -// A. We are caching the screen representations (LyXText) of the -// documents (Buffer,Paragraph) for specific BufferView widths. -// Q. Why the cache? -// A. It is not really needed, but it speeds things up a lot -// when you have more than one document loaded at once since a total -// rebreak (reformatting) need not be done when switching between -// documents. When the cache is in function a document only needs to be -// formatted upon loading and when the with of the BufferView changes. -// Later it will also be unneccessary to reformat when having two -// BufferViews of equal width with the same document, a simple copy -// of the LyXText structure will do. -// Invariant for the TextCache: -// - The buffer of the text in the TextCache _must_ exists -// in the bufferlist. -// - For a text in the TextCache there _must not_ be an equivalent -// text in any BufferView. (same buffer and width). -// Among others this mean: -// - When a document is closed all trace of it must be removed from -// the TextCache. -// Scenarios: -// I believe there are only three possible scenarios where the two first -// are also covered by the third. -// - The simplest scenario is what we have now, a single -// BufferView only. -// o Opening -// Nothing to do with the TextCache is done when opening a file. -// o Switching -// We switch from buffer A to buffer B. -// * A's text is cached in TextCache. -// * We make a search for a text in TextCache that fits B -// (same buffer and same width). -// o Horizontal resize -// If the BufferView's width (LyXView) is horizontally changed all -// the entries in the TextCache are deleted. (This causes -// reformat of all loaded documents when next viewed) -// o Close -// When a buffer is closed we don't have to do anything, because -// to close a single buffer it is required to only exist in the -// BufferView and not in the TextCache. Upon LFUN_QUIT we -// don't really care since everything is deleted anyway. -// - The next scenario is when we have several BufferViews (in one or -// more LyXViews) of equal width. -// o Opening -// Nothing to do with the TextCache is done when opening a file. -// o Switching -// We switch from buffer A to buffer B. -// * If A is in another Bufferview we do not put it into TextCache. -// else we put A into TextCache. -// * If B is viewed in another BufferView we make a copy of its -// text and use that, else we search in TextCache for a match. -// (same buffer same width) -// o Horizontal resize -// If the BufferView's width (LyXView) is horisontaly changed all -// the entries in the TextCache is deleted. (This causes -// reformat of all loaded documents when next viewed) -// o Close -// - The last scenario should cover both the previous ones, this time -// we have several BufferViews (in one or more LyXViews) with no -// limitations on width. (And if you wonder why the two other -// senarios are needed... I used them to get to this one.) -// o Opening -// Nothing to do with the TextCache is done when opening a file. -// o Switching -// We switch from buffer A to buffer B. -// o Horisontal rezize -// o Close - -/** This class is used to cache generated LyXText's. - The LyXText's is used by the BufferView to visualize the contents - of a buffer and its paragraphs. Instead of deleting the LyXText when - we switch from one document to another we cache it here so that when - we switch back we do not have to reformat. This makes switching very - fast at the expense of a bit higher memory usage. -*/ -class TextCache { -public: - /// - typedef std::map > Cache; - - /// - typedef Cache::value_type value_type; - - /** Returns a pointer to a LyXText that fits the provided buffer - and width. Of there is no match 0 is returned. */ - LyXText * findFit(Buffer * b, int p); - /** Lists all the LyXText's currently in the cache. - Uses msg as header for the list. */ - void show(std::ostream & o, std::string const & msg); - /// Gives info on a single LyXText (buffer and width) - static void show(std::ostream & o, value_type const &); - /** Adds a LyXText to the cache iff its buffer is - present in bufferlist. */ - void add(Buffer *, int witdth, LyXText *); - /** Clears the cache. Deletes all LyXText's and releases - the allocated memory. */ - void clear(); - /// Removes all LyXText's that has buffer b from the TextCache - void removeAllWithBuffer(Buffer * b); -private: - /// The cache. - Cache cache; -}; - -/// -extern TextCache textcache; -#endif diff --git a/src/bufferlist.C b/src/bufferlist.C index aeb2d32a0c..7ae6d255d5 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -21,7 +21,6 @@ #include "lyx_cb.h" #include "lyx_main.h" #include "paragraph.h" -#include "TextCache.h" #include "frontends/Alert.h" @@ -119,12 +118,8 @@ void BufferList::release(Buffer * buf) BOOST_ASSERT(buf); BufferStorage::iterator it = find(bstore.begin(), bstore.end(), buf); if (it != bstore.end()) { - // Make sure that we don't store a LyXText in - // the textcache that points to the buffer - // we just deleted. Buffer * tmp = (*it); bstore.erase(it); - textcache.removeAllWithBuffer(tmp); delete tmp; } } @@ -143,10 +138,6 @@ Buffer * BufferList::newBuffer(string const & s, bool ronly) void BufferList::closeAll() { - // Since we are closing we can just as well delete all - // in the textcache this will also speed the closing/quiting up a bit. - textcache.clear(); - while (!bstore.empty()) { close(bstore.front(), false); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index d9d1c4b78a..2ee3563b1f 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -48,7 +48,6 @@ #include "lyxvc.h" #include "paragraph.h" #include "ParagraphParameters.h" -#include "TextCache.h" #include "undo.h" #include "insets/insetcommand.h" @@ -1583,12 +1582,6 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) // handle the screen font changes. lyxrc.set_font_norm_type(); lyx_gui::update_fonts(); - // We also need to empty the textcache so that - // the buffer will be formatted correctly after - // a zoom change. - textcache.clear(); - // Of course we should only do the resize and the textcache.clear - // if values really changed...but not very important right now. (Lgb) // All visible buffers will need resize view()->resize(); view()->update();