commit 2fe650f77f520b31e6e0517eae39d874eeec53a6
Author: Georg Baum <[email protected]>
Date:   Mon Jul 7 22:05:10 2014 +0200

    Make BufferList::fileNames() threadsafe
    
    Using a static variable here was premature optimization: fileNames() is only
    called from GuiRef (directly or indirectly), and since this is a dialog the
    copying of a FileNameList is not noticeable at all.

diff --git a/src/BufferList.cpp b/src/BufferList.cpp
index 341ddf4..c253282 100644
--- a/src/BufferList.cpp
+++ b/src/BufferList.cpp
@@ -154,10 +154,9 @@ void BufferList::closeAll()
 }
 
 
-FileNameList const & BufferList::fileNames() const
+FileNameList BufferList::fileNames() const
 {
-       static FileNameList nvec;
-       nvec.clear();
+       FileNameList nvec;
        BufferStorage::const_iterator it = bstore.begin();
        BufferStorage::const_iterator end = bstore.end();
        for (; it != end; ++it) {
@@ -347,7 +346,7 @@ void BufferList::recordCurrentAuthor(Author const & author)
 
 int BufferList::bufferNum(FileName const & fname) const
 {
-       FileNameList const & buffers = fileNames();
+       FileNameList const buffers(fileNames());
        FileNameList::const_iterator cit =
                find(buffers.begin(), buffers.end(), fname);
        if (cit == buffers.end())
diff --git a/src/BufferList.h b/src/BufferList.h
index 95df26a..4f9cb95 100644
--- a/src/BufferList.h
+++ b/src/BufferList.h
@@ -66,7 +66,7 @@ public:
        void closeAll();
 
        /// returns a vector with all the buffers filenames
-       support::FileNameList const & fileNames() const;
+       support::FileNameList fileNames() const;
 
        /// return true if no buffers loaded
        bool empty() const;
diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp
index 141c67b..c0e6842 100644
--- a/src/frontends/qt4/GuiRef.cpp
+++ b/src/frontends/qt4/GuiRef.cpp
@@ -251,7 +251,7 @@ void GuiRef::updateContents()
 
        // insert buffer list
        bufferCO->clear();
-       FileNameList const & buffers = theBufferList().fileNames();
+       FileNameList const buffers(theBufferList().fileNames());
        for (FileNameList::const_iterator it = buffers.begin();
             it != buffers.end(); ++it) {
                bufferCO->addItem(toqstr(makeDisplayPath(it->absFileName())));
@@ -455,7 +455,8 @@ void GuiRef::updateRefs()
        refs_.clear();
        int const the_buffer = bufferCO->currentIndex();
        if (the_buffer != -1) {
-               FileName const & name = theBufferList().fileNames()[the_buffer];
+               FileNameList const names(theBufferList().fileNames());
+               FileName const & name = names[the_buffer];
                Buffer const * buf = theBufferList().getBuffer(name);
                buf->getLabelList(refs_);
        }

Reply via email to