Le 21/07/15 15:36, Scott Kostyshak a écrit :
I propose that you land it in master. If something goes very wrong, we
can always revert it without you here. This is why I really appreciate
your having done the work on a branch (as opposed to master directly),
so it is easy to merge/unmerge.

I landed in master now. I tried a bit to use QCache to make call to speed-up computation of string width, but it des not sem to work better than a normal std::map on my older iMac. It might be that hash tables are not good when keys are long-ish strings. I attach the patch in case somebody good at Qt and/or STL wants to have a look

JMarc

From f76e728dbc026e54ff6bdb9d5cf7568012a148e7 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Tue, 21 Jul 2015 23:19:40 +0200
Subject: [PATCH] Use QCache to cache string width

This buys us a hash table and some LRU eviction of old strings.
---
 src/frontends/qt4/GuiFontLoader.cpp  | 12 ++++++++----
 src/frontends/qt4/GuiFontMetrics.cpp | 15 ++++++---------
 src/frontends/qt4/GuiFontMetrics.h   |  5 ++---
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/frontends/qt4/GuiFontLoader.cpp 
b/src/frontends/qt4/GuiFontLoader.cpp
index 69f1ed2..22df6e8 100644
--- a/src/frontends/qt4/GuiFontLoader.cpp
+++ b/src/frontends/qt4/GuiFontLoader.cpp
@@ -269,9 +269,9 @@ static QString makeFontName(QString const & family, QString 
const & foundry)
 }
 
 
-GuiFontInfo::GuiFontInfo(FontInfo const & f)
-       : metrics(QFont())
+static QFont makeQFont(FontInfo const & f)
 {
+       QFont font;
        QString const pat = symbolFamily(f.family());
        if (!pat.isEmpty()) {
                bool ok;
@@ -346,11 +346,15 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f)
                               * lyxrc.zoom / 100.0);
 
        LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF());
-
-       metrics = GuiFontMetrics(font);
+       return font;
 }
 
 
+GuiFontInfo::GuiFontInfo(FontInfo const & f)
+       : font(makeQFont(f)), metrics(font)
+{}
+
+
 bool FontLoader::available(FontInfo const & f)
 {
        // FIXME THREAD
diff --git a/src/frontends/qt4/GuiFontMetrics.cpp 
b/src/frontends/qt4/GuiFontMetrics.cpp
index e41ef3c..54d60fd 100644
--- a/src/frontends/qt4/GuiFontMetrics.cpp
+++ b/src/frontends/qt4/GuiFontMetrics.cpp
@@ -12,7 +12,6 @@
 #include <config.h>
 
 #include "GuiFontMetrics.h"
-
 #include "qt_helpers.h"
 
 #include "Dimension.h"
@@ -120,14 +119,12 @@ int GuiFontMetrics::rbearing(char_type c) const
 
 int GuiFontMetrics::width(docstring const & s) const
 {
-       int w = 0;
-       map<docstring, int>::const_iterator it = strwidth_cache_.find(s);
-       if (it != strwidth_cache_.end()) {
-               w = it->second;
-       } else {
-               w = metrics_.width(toqstr(s));
-               strwidth_cache_[s] = w;
-       }
+       QString const qs = toqstr(s);
+       int * pw = strwidth_cache_[qs];
+       if (pw)
+               return *pw;
+       int w = metrics_.width(qs);
+       strwidth_cache_.insert(qs, new int(w));
        return w;
 }
 
diff --git a/src/frontends/qt4/GuiFontMetrics.h 
b/src/frontends/qt4/GuiFontMetrics.h
index a382253..8797e53 100644
--- a/src/frontends/qt4/GuiFontMetrics.h
+++ b/src/frontends/qt4/GuiFontMetrics.h
@@ -16,8 +16,7 @@
 
 #include "support/docstring.h"
 
-#include <map>
-
+#include <QCache>
 #include <QFont>
 #include <QFontMetrics>
 #include <QHash>
@@ -71,7 +70,7 @@ private:
 
        /// Cache of string widths
        /// FIXME Try to use a QHash (this requires to define qHash(docstring))
-       mutable std::map<docstring, int> strwidth_cache_;
+       mutable QCache<QString, int> strwidth_cache_;
 
        struct AscendDescend {
                int ascent;
-- 
2.1.4

Reply via email to