]> git.lyx.org Git - lyx.git/commitdiff
Cache the value of GuiFontMetrics::lbearing().
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 20 Mar 2019 09:56:16 +0000 (10:56 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 21 Mar 2019 17:43:37 +0000 (18:43 +0100)
This seems to be necessary on windows, where math editing can get very
slow. Note that other methods like rbearing already use a cache.

In the future all these caches for single characters shall be unified.

(cherry picked from commit d3979e798cd9c85041bb5e6158002384a8cddb8c)

src/frontends/qt4/GuiFontMetrics.cpp
src/frontends/qt4/GuiFontMetrics.h
status.23x

index 8ed82280c0bdc33efaf5e658c07bb618dba4f315..63f61f2e3f619c2806140e83f068524b83c23a72 100644 (file)
@@ -135,20 +135,29 @@ int GuiFontMetrics::strikeoutPos() const
 }
 
 
+namespace {
+int const outOfLimitMetric = -10000;
+}
+
+
 int GuiFontMetrics::lbearing(char_type c) const
 {
-       if (!is_utf16(c))
+       int value = lbearing_cache_.value(c, outOfLimitMetric);
+       if (value != outOfLimitMetric)
+               return value;
+
+       if (is_utf16(c))
+               value = metrics_.leftBearing(ucs4_to_qchar(c));
+       else {
                // FIXME: QFontMetrics::leftBearing does not support the
                //        full unicode range. Once it does, we could use:
-               //return metrics_.leftBearing(toqstr(docstring(1, c)));
-               return 0;
-
-       return metrics_.leftBearing(ucs4_to_qchar(c));
-}
+               // metrics_.leftBearing(toqstr(docstring(1, c)));
+               value = 0;
+       }
 
+       lbearing_cache_.insert(c, value);
 
-namespace {
-int const outOfLimitMetric = -10000;
+       return value;
 }
 
 
index 3f50dfe5d29902d0516e2b27c3ca2ec32fa4d4e4..6cea40f3ecccda69d6da00161b901d4eb74b5811 100644 (file)
@@ -101,6 +101,8 @@ private:
        /// fill in \c metrics_cache_ at specified value.
        AscendDescend const fillMetricsCache(char_type) const;
 
+       /// Cache of char left bearings
+       mutable QHash<char_type, int> lbearing_cache_;
        /// Cache of char right bearings
        mutable QHash<char_type, int> rbearing_cache_;
 
index d7afa3592bec82ef6ed591c78f16b05b170ca801..29f9d20addf102cbcd784ee7ab594437de351d46 100644 (file)
@@ -51,6 +51,8 @@ What's new
 
 - Fix bad error message (bug 11486).
 
+- Improve performance on Windows with lots of math insets.
+
 
 * DOCUMENTATION AND LOCALIZATION