commit 425cbfc1a3ac4208d9db8129fdc793e02ec83578
Author: Thibaut Cuvelier <[email protected]>
Date: Mon Oct 27 23:17:09 2025 +0100
Remove QThreadLocal<int> in favour of a C++ standard solution:
`thread_local`.
---
src/insets/InsetIndex.cpp | 11 +++--------
src/xml.cpp | 9 ++++-----
2 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
index e1d61bb43f..83406e6776 100644
--- a/src/insets/InsetIndex.cpp
+++ b/src/insets/InsetIndex.cpp
@@ -485,23 +485,18 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams
const & runparams) const
} else {
// Append an ID if uniqueness is not guaranteed across
the document.
static QThreadStorage<set<docstring>> tKnownTermLists;
- static QThreadStorage<int> tID;
+ thread_local int tID = 0;
set<docstring> &knownTermLists =
tKnownTermLists.localData();
- int &ID = tID.localData();
-
- if (!tID.hasLocalData()) {
- tID.localData() = 0;
- }
// Modify the index terms to add the unique ID if
needed.
docstring newIndexTerms = indexTerms;
if (knownTermLists.find(indexTerms) !=
knownTermLists.end()) {
- newIndexTerms += from_ascii(string("-") +
to_string(ID));
+ newIndexTerms += from_ascii(string("-") +
to_string(tID));
// Only increment for the end of range, so that
the same number is used for the start of range.
if (hasEndRange) {
- ID++;
+ tID++;
}
}
diff --git a/src/xml.cpp b/src/xml.cpp
index 34c8e986da..c8e3fb4f88 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -626,7 +626,7 @@ docstring xml::cleanID(docstring const & orig)
// This code could be improved: it uses Qt outside the GUI part. Any
TLS implementation could do the trick.
typedef map<docstring, docstring> MangledMap;
static QThreadStorage<MangledMap> tMangledNames;
- static QThreadStorage<int> tMangleID;
+ thread_local int tMangleID = 0;
// If the name is already known, just return it.
MangledMap & mangledNames = tMangledNames.localData();
@@ -662,10 +662,9 @@ docstring xml::cleanID(docstring const & orig)
// This avoids having a clash if satisfying XML requirements for ID
makes two IDs identical, like "a:b" and "a!b",
// as both of them would be transformed as "a.b". With this procedure,
one will become "a.b" and the other "a.b-1".
if (mangle && mangledNames.find(content) != mangledNames.end()) {
- int & mangleID = tMangleID.localData();
- if (mangleID > 0)
- content += "-" + convert<docstring>(mangleID);
- mangleID += 1;
+ if (tMangleID > 0)
+ content += "-" + convert<docstring>(tMangleID);
+ tMangleID += 1;
}
// Save the new ID to avoid recomputing it afterwards and to ensure
stability over the document.
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs