commit 82d4f1a446260333ef1590f3622196e7c76e414d Author: Guillaume Munch <g...@lyx.org> Date: Sun Jul 31 00:42:51 2016 +0100
Replace static with thread_local when used for caching thread_local is a per-thread static variable, so it is thread-safe and can be used for caching purpose. Remove the cache for parameter lists as discussed on the list http://mid.gmane.org/6e871431-0e87-ed2a-3e31-b63356c23...@lyx.org. (requires gcc >= 4.8) --- src/frontends/qt4/GuiCitation.cpp | 1 + src/frontends/qt4/GuiDocument.cpp | 13 +------------ src/frontends/qt4/GuiFontLoader.cpp | 10 +++++++--- src/frontends/qt4/GuiInclude.cpp | 13 +------------ src/frontends/qt4/GuiListings.cpp | 14 +------------- src/frontends/qt4/GuiPainter.cpp | 7 ++++++- src/frontends/qt4/GuiSymbols.cpp | 5 ++++- 7 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index 028e874..a99db88 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -571,6 +571,7 @@ void GuiCitation::findKey(BiblioInfo const & bi, bool case_sensitive, bool reg_exp, bool reset) { // FIXME THREAD + // This should be moved to a class member. // Used for optimisation: store last searched string. static QString last_searched_string; // Used to disable the above optimisation. diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index e116001..7d6e865 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -1496,21 +1496,10 @@ void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int) QString GuiDocument::validateListingsParameters() { - // use a cache here to avoid repeated validation - // of the same parameters - // FIXME THREAD - static string param_cache; - static QString msg_cache; - if (listingsModule->bypassCB->isChecked()) return QString(); - string params = fromqstr(listingsModule->listingsED->toPlainText()); - if (params != param_cache) { - param_cache = params; - msg_cache = toqstr(InsetListingsParams(params).validate()); - } - return msg_cache; + return toqstr(InsetListingsParams(params).validate()); } diff --git a/src/frontends/qt4/GuiFontLoader.cpp b/src/frontends/qt4/GuiFontLoader.cpp index cc092f5..2dacc42 100644 --- a/src/frontends/qt4/GuiFontLoader.cpp +++ b/src/frontends/qt4/GuiFontLoader.cpp @@ -373,9 +373,13 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f) bool FontLoader::available(FontInfo const & f) { - // FIXME THREAD - static vector<int> cache_set(NUM_FAMILIES, false); - static vector<int> cache(NUM_FAMILIES, false); +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 6) + static vector<bool> cache_set(NUM_FAMILIES, false); + static vector<bool> cache(NUM_FAMILIES, false); +#else + thread_local vector<bool> cache_set(NUM_FAMILIES, false); + thread_local vector<bool> cache(NUM_FAMILIES, false); +#endif FontFamily family = f.family(); #ifdef Q_OS_MAC diff --git a/src/frontends/qt4/GuiInclude.cpp b/src/frontends/qt4/GuiInclude.cpp index e1fc275..b02fd91 100644 --- a/src/frontends/qt4/GuiInclude.cpp +++ b/src/frontends/qt4/GuiInclude.cpp @@ -91,21 +91,10 @@ void GuiInclude::change_adaptor() docstring GuiInclude::validate_listings_params() { - // use a cache here to avoid repeated validation - // of the same parameters - // FIXME THREAD - static string param_cache = string(); - static docstring msg_cache = docstring(); - if (typeCO->currentIndex() != 3 || bypassCB->isChecked()) return docstring(); - string params = fromqstr(listingsED->toPlainText()); - if (params != param_cache) { - param_cache = params; - msg_cache = InsetListingsParams(params).validate(); - } - return msg_cache; + return InsetListingsParams(params).validate(); } diff --git a/src/frontends/qt4/GuiListings.cpp b/src/frontends/qt4/GuiListings.cpp index da12882..bc7fdb8 100644 --- a/src/frontends/qt4/GuiListings.cpp +++ b/src/frontends/qt4/GuiListings.cpp @@ -346,21 +346,9 @@ string GuiListings::construct_params() docstring GuiListings::validate_listings_params() { - // use a cache here to avoid repeated validation - // of the same parameters - // FIXME THREAD - static string param_cache; - static docstring msg_cache; - if (bypassCB->isChecked()) return docstring(); - - string params = construct_params(); - if (params != param_cache) { - param_cache = params; - msg_cache = InsetListingsParams(params).validate(); - } - return msg_cache; + return InsetListingsParams(construct_params()).validate(); } diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp index 65d95f6..5156dc0 100644 --- a/src/frontends/qt4/GuiPainter.cpp +++ b/src/frontends/qt4/GuiPainter.cpp @@ -208,11 +208,16 @@ void GuiPainter::lines(int const * xp, int const * yp, int np, return; // double the size if needed - // FIXME THREAD +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 6) static QVector<QPoint> points(32); +#else + thread_local QVector<QPoint> points(32); +#endif if (np > points.size()) points.resize(2 * np); + // Note: the proper way to not get blurry vertical and horizontal lines is + // to add 0.5 to all coordinates. bool antialias = false; for (int i = 0; i < np; ++i) { points[i].setX(xp[i]); diff --git a/src/frontends/qt4/GuiSymbols.cpp b/src/frontends/qt4/GuiSymbols.cpp index a08d7e5..f4a547e 100644 --- a/src/frontends/qt4/GuiSymbols.cpp +++ b/src/frontends/qt4/GuiSymbols.cpp @@ -152,8 +152,11 @@ const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks); QString getBlock(char_type c) { // store an educated guess for the next search - // FIXME THREAD +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 6) static int lastBlock = 0; +#else + thread_local int lastBlock = 0; +#endif // "clever reset" if (c < 0x7f)