From e9921406856bec5a30a5e55559a3a1546c869403 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 9 Aug 2010 17:01:51 +0000 Subject: [PATCH] More work toward speeding up the bibfile caching stuff. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35103 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 28 +++++++++++++++++++++------- src/Buffer.h | 8 +++++--- src/BufferView.cpp | 12 ++++++++---- src/insets/InsetBibtex.cpp | 3 ++- src/insets/InsetInclude.cpp | 24 ++---------------------- src/insets/InsetInclude.h | 14 -------------- 6 files changed, 38 insertions(+), 51 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index d4037ee181..bac5e52655 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -256,6 +256,8 @@ public: mutable BiblioInfo bibinfo_; /// whether the bibinfo cache is valid bool bibinfo_cache_valid_; + /// whether the bibfile cache is valid + bool bibfile_cache_valid_; /// Cache of timestamps of .bib files map bibfile_status_; @@ -323,7 +325,8 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_, read_only(readonly_), filename(file), file_fully_loaded(false), toc_backend(owner), macro_lock(false), timestamp_(0), checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false), - cloned_buffer_(cloned_buffer), doing_export(false), parent_buffer(0) + bibfile_cache_valid_(false), cloned_buffer_(cloned_buffer), + doing_export(false), parent_buffer(0) { if (!cloned_buffer_) { temppath = createBufferTmpDir(); @@ -338,6 +341,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_, bibfiles_cache_ = cloned_buffer_->d->bibfiles_cache_; bibinfo_ = cloned_buffer_->d->bibinfo_; bibinfo_cache_valid_ = cloned_buffer_->d->bibinfo_cache_valid_; + bibfile_cache_valid_ = cloned_buffer_->d->bibfile_cache_valid_; bibfile_status_ = cloned_buffer_->d->bibfile_status_; } @@ -1716,18 +1720,22 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const } else if (it->lyxCode() == INCLUDE_CODE) { InsetInclude & inset = static_cast(*it); - inset.updateBibfilesCache(); + Buffer const * const incbuf = inset.getChildBuffer(); + if (!incbuf) + continue; + incbuf->updateBibfilesCache(UpdateChildOnly); support::FileNameList const & bibfiles = - inset.getBibfilesCache(); + incbuf->getBibfilesCache(UpdateChildOnly); if (!bibfiles.empty()) { d->bibfiles_cache_.insert(d->bibfiles_cache_.end(), bibfiles.begin(), bibfiles.end()); // the bibinfo cache is now invalid d->bibinfo_cache_valid_ = false; - } + } } } + d->bibfile_cache_valid_ = true; } @@ -1737,6 +1745,11 @@ void Buffer::invalidateBibinfoCache() } +void Buffer::invalidateBibfileCache() +{ + d->bibfile_cache_valid_ = false; +} + support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const { // If this is a child document, use the parent's cache instead. @@ -1744,9 +1757,8 @@ support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const if (pbuf && scope != UpdateChildOnly) return pbuf->getBibfilesCache(); - // We update the cache when first used instead of at loading time. - if (d->bibfiles_cache_.empty()) - const_cast(this)->updateBibfilesCache(scope); + if (!d->bibfile_cache_valid_) + this->updateBibfilesCache(scope); return d->bibfiles_cache_; } @@ -1785,6 +1797,8 @@ void Buffer::checkBibInfoCache() const } } + // FIXME Don't do this here, but instead gather them as we go through + // updateBuffer(). if (!d->bibinfo_cache_valid_) { d->bibinfo_.clear(); for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) diff --git a/src/Buffer.h b/src/Buffer.h index 54e66ab3dd..ef6e3274b8 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -342,9 +342,6 @@ public: */ void validate(LaTeXFeatures &) const; - /// Update the list of all bibfiles in use (including bibfiles - /// of loaded child documents). - void updateBibfilesCache(UpdateScope scope = UpdateMaster) const; /// Return the list with all bibfiles in use (including bibfiles /// of loaded child documents). support::FileNameList const & @@ -354,6 +351,8 @@ public: /// Calling this method invalidates the cache and so requires a /// re-read. void invalidateBibinfoCache(); + /// This invalidates the cache of files we need to check. + void invalidateBibfileCache(); /// Updates the cached bibliography information. /// Note that you MUST call this method to update the cache. It will /// not happen otherwise. (Currently, it is called at the start of @@ -579,6 +578,9 @@ private: bool fromString = false); /// void getLanguages(std::set &) const; + /// Update the list of all bibfiles in use (including bibfiles + /// of loaded child documents). + void updateBibfilesCache(UpdateScope scope = UpdateMaster) const; /// Use the Pimpl idiom to hide the internals. class Impl; diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 2ce84ec2b9..357fd77845 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1565,8 +1565,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) InsetBibtex * inset = getInsetByCode(tmpcur, BIBTEX_CODE); if (inset) { - if (inset->addDatabase(cmd.argument())) - buffer_.updateBibfilesCache(); + if (inset->addDatabase(cmd.argument())) { + buffer_.invalidateBibfileCache(); + dr.forceBufferUpdate(); + } } break; } @@ -1577,8 +1579,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) InsetBibtex * inset = getInsetByCode(tmpcur, BIBTEX_CODE); if (inset) { - if (inset->delDatabase(cmd.argument())) - buffer_.updateBibfilesCache(); + if (inset->delDatabase(cmd.argument())) { + buffer_.invalidateBibfileCache(); + dr.forceBufferUpdate(); + } } break; } diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 5c673c88c1..c726e2680f 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -101,7 +101,8 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd) } // setParams(p); - buffer().updateBibfilesCache(); + buffer().invalidateBibfileCache(); + cur.forceBufferUpdate(); break; } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 66d9fc6a4d..9458aba8f2 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -235,7 +235,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_INSET_MODIFY: { - // It should be OK just to invalidate the cache is setParams() + // It should be OK just to invalidate the cache in setParams() // If not.... // child_buffer_ = 0; InsetCommandParams p(INCLUDE_CODE); @@ -338,7 +338,7 @@ void InsetInclude::setParams(InsetCommandParams const & p) if (type(params()) == INPUT) add_preview(*preview_, *this, buffer()); - buffer().updateBibfilesCache(); + buffer().invalidateBibfileCache(); } @@ -842,26 +842,6 @@ void InsetInclude::fillWithBibKeys(BiblioInfo & keys, } -void InsetInclude::updateBibfilesCache() -{ - Buffer const * const child = getChildBuffer(); - if (child) - child->updateBibfilesCache(Buffer::UpdateChildOnly); -} - - -support::FileNameList const & - InsetInclude::getBibfilesCache() const -{ - Buffer const * const child = getChildBuffer(); - if (child) - return child->getBibfilesCache(Buffer::UpdateChildOnly); - - static support::FileNameList const empty; - return empty; -} - - void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const { LASSERT(mi.base.bv, /**/); diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index f8c4065c97..cfc990cbcc 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -61,20 +61,6 @@ public: */ void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const; - /** Update the cache with all bibfiles in use of the child buffer - * (including bibfiles of grandchild documents). - * Does nothing if the child document is not loaded to prevent - * automatic loading of all child documents upon loading the master. - * \param buffer the Buffer containing this inset. - */ - void updateBibfilesCache(); - /** Return the cache with all bibfiles in use of the child buffer - * (including bibfiles of grandchild documents). - * Return an empty vector if the child doc is not loaded. - * \param buffer the Buffer containing this inset. - */ - support::FileNameList const & - getBibfilesCache() const; /// bool hasSettings() const { return true; } /// -- 2.39.2