Le 20/03/2019 à 11:46, Jean-Marc Lasgouttes a écrit :
commit d3979e798cd9c85041bb5e6158002384a8cddb8c
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Wed Mar 20 10:56:16 2019 +0100

     Cache the value of GuiFontMetrics::lbearing().
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.

This should alleviate the performance issues on windows. I will see tonight on my windows machine how effective it is. At least it is much less intrusive than trying to reduce the amount of painting.

If it makes LyX on windows faster, this will be candidate for 2.3.3.

JMarc

---
  src/frontends/qt4/GuiFontMetrics.cpp |   25 +++++++++++++++++--------
  src/frontends/qt4/GuiFontMetrics.h   |    2 ++
  2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/frontends/qt4/GuiFontMetrics.cpp 
b/src/frontends/qt4/GuiFontMetrics.cpp
index b57f514..5f70c8d 100644
--- a/src/frontends/qt4/GuiFontMetrics.cpp
+++ b/src/frontends/qt4/GuiFontMetrics.cpp
@@ -148,20 +148,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;
  }
diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h
index 6d50d35..44897c4 100644
--- a/src/frontends/qt4/GuiFontMetrics.h
+++ b/src/frontends/qt4/GuiFontMetrics.h
@@ -103,6 +103,8 @@ private:
        /// fill in \c metrics_cache_ at specified value.
        AscendDescend const fillMetricsCache(char_type) const;
+ /// Cache of char leftt bearings
+       mutable QHash<char_type, int> lbearing_cache_;
        /// Cache of char right bearings
        mutable QHash<char_type, int> rbearing_cache_;

Reply via email to