]> git.lyx.org Git - features.git/commitdiff
Make BufferList::fileNames() threadsafe
authorGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:51:40 +0000 (12:51 +0200)
committerGeorg Baum <baum@lyx.org>
Sat, 5 Jul 2014 10:51:40 +0000 (12:51 +0200)
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.

src/BufferList.cpp
src/BufferList.h
src/frontends/qt4/GuiRef.cpp

index de5a7ab2ad56fd327d8bbe47aac146b1d2f55c77..c253282b795c029ea244769362d4fee5d9e6ca5c 100644 (file)
@@ -154,11 +154,9 @@ void BufferList::closeAll()
 }
 
 
 }
 
 
-FileNameList const & BufferList::fileNames() const
+FileNameList BufferList::fileNames() const
 {
 {
-       // FIXME THREAD
-       static FileNameList nvec;
-       nvec.clear();
+       FileNameList nvec;
        BufferStorage::const_iterator it = bstore.begin();
        BufferStorage::const_iterator end = bstore.end();
        for (; it != end; ++it) {
        BufferStorage::const_iterator it = bstore.begin();
        BufferStorage::const_iterator end = bstore.end();
        for (; it != end; ++it) {
@@ -348,7 +346,7 @@ void BufferList::recordCurrentAuthor(Author const & author)
 
 int BufferList::bufferNum(FileName const & fname) const
 {
 
 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())
        FileNameList::const_iterator cit =
                find(buffers.begin(), buffers.end(), fname);
        if (cit == buffers.end())
index 95df26aa6df9e9b9757e5bb00d34eb3d7d979ef4..4f9cb95c05cb6d177aa3637ed9a8a01bfebe5832 100644 (file)
@@ -66,7 +66,7 @@ public:
        void closeAll();
 
        /// returns a vector with all the buffers filenames
        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;
 
        /// return true if no buffers loaded
        bool empty() const;
index 141c67bc13733ac413da9d2c4c0e39eb0f0f94a6..c0e6842c36d768491a6495a21c690cf89ec41cd9 100644 (file)
@@ -251,7 +251,7 @@ void GuiRef::updateContents()
 
        // insert buffer list
        bufferCO->clear();
 
        // 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())));
        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) {
        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_);
        }
                Buffer const * buf = theBufferList().getBuffer(name);
                buf->getLabelList(refs_);
        }