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
This commit is contained in:
Richard Heck 2010-08-09 17:01:51 +00:00
parent 4509607bf6
commit e992140685
6 changed files with 38 additions and 51 deletions

View File

@ -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<FileName, time_t> 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,9 +1720,12 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const
} else if (it->lyxCode() == INCLUDE_CODE) {
InsetInclude & inset =
static_cast<InsetInclude &>(*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(),
@ -1728,6 +1735,7 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const
}
}
}
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<Buffer *>(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)

View File

@ -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<Language const *> &) 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;

View File

@ -1565,8 +1565,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
InsetBibtex * inset = getInsetByCode<InsetBibtex>(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<InsetBibtex>(tmpcur,
BIBTEX_CODE);
if (inset) {
if (inset->delDatabase(cmd.argument()))
buffer_.updateBibfilesCache();
if (inset->delDatabase(cmd.argument())) {
buffer_.invalidateBibfileCache();
dr.forceBufferUpdate();
}
}
break;
}

View File

@ -101,7 +101,8 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
}
//
setParams(p);
buffer().updateBibfilesCache();
buffer().invalidateBibfileCache();
cur.forceBufferUpdate();
break;
}

View File

@ -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, /**/);

View File

@ -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; }
///