]> git.lyx.org Git - lyx.git/blobdiff - src/sgml.cpp
This is LyX 2.2.0
[lyx.git] / src / sgml.cpp
index 4842b07912e8f2f4524782a12093a5b3865174b8..75802c2bd44d2113da87253c0c31ffb0fc267df0 100644 (file)
@@ -28,6 +28,7 @@
 #include "support/textutils.h"
 
 #include <map>
+#include <QThreadStorage>
 
 using namespace std;
 using namespace lyx::support;
@@ -102,8 +103,11 @@ docstring sgml::escapeString(docstring const & raw)
 }
 
 
-docstring const sgml::uniqueID(docstring const label)
+docstring const sgml::uniqueID(docstring const label)
 {
+       // FIXME THREAD
+       // It seems unlikely there could be a problem here,
+       // but we could have concurrent access, in principle.
        static unsigned int seed = 1000;
        return label + convert<docstring>(++seed);
 }
@@ -133,8 +137,10 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
        docstring content;
 
        typedef map<docstring, docstring> MangledMap;
-       static MangledMap mangledNames;
-       static int mangleID = 1;
+       static QThreadStorage<MangledMap> tMangledNames;
+       static QThreadStorage<int> tMangleID;
+
+       MangledMap & mangledNames = tMangledNames.localData();
 
        MangledMap::const_iterator const known = mangledNames.find(orig);
        if (known != mangledNames.end())
@@ -163,9 +169,10 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
                }
        }
 
-       if (mangle)
+       if (mangle) {
+               int & mangleID = tMangleID.localData();
                content += "-" + convert<docstring>(mangleID++);
-       else if (isDigitASCII(content[content.size() - 1]))
+       else if (isDigitASCII(content[content.size() - 1]))
                content += ".";
 
        mangledNames[orig] = content;