Skip to content

Commit

Permalink
Make initialization of static variable thread safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse authored and 23rd committed Feb 5, 2020
1 parent 195c2b8 commit 691cda5
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions spellcheck/spellcheck_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ QChar::Script WordScript(const QStringRef &word) {
: firstLetter->script();
}

bool IsWordSkippable(const QStringRef &word) {
static auto systemScripts = std::vector<QChar::Script>();
if (!systemScripts.size()) {
class SystemScripts {
std::vector<QChar::Script> systemScripts;
public:

SystemScripts() {
std::vector<QString> languages;
Platform::Spellchecker::KnownLanguages(&languages);
systemScripts = (
Expand All @@ -238,16 +240,24 @@ bool IsWordSkippable(const QStringRef &word) {
systemScripts = { QChar::Script_Common };
}
}
const auto wordScript = WordScript(word);
if (ranges::find(systemScripts, wordScript) == end(systemScripts)) {
return true;

bool IsWordSkippable(const QStringRef &word) const {
const auto wordScript = WordScript(word);
if (ranges::find(systemScripts, wordScript) == end(systemScripts)) {
return true;
}
return ranges::find_if(word, [&](QChar c) {
return (c.script() != wordScript)
&& !IsAcuteAccentChar(c)
&& (c.unicode() != '\'') // Patched Qt to make it a non-separator.
&& (c.unicode() != '_'); // This is not a word separator.
}) != word.end();
}
return ranges::find_if(word, [&](QChar c) {
return (c.script() != wordScript)
&& !IsAcuteAccentChar(c)
&& (c.unicode() != '\'') // Patched Qt to make it a non-separator.
&& (c.unicode() != '_'); // This is not a word separator.
}) != word.end();
};

bool IsWordSkippable(const QStringRef &word) {
static SystemScripts systemScripts;
return systemScripts.IsWordSkippable(word);
}

MisspelledWords RangesFromText(
Expand Down

0 comments on commit 691cda5

Please sign in to comment.