]> git.lyx.org Git - lyx.git/commitdiff
Cache the value of FontMetrics::xHeight()
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 15 Jul 2023 17:39:14 +0000 (19:39 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 15 Jul 2023 21:32:59 +0000 (23:32 +0200)
This value is computed for the metrics of *every* Mathdata and hotspot
says that it counts for 9% of total on math-heavy "branch-test.lyx"
file. I am not sure that real world agrees with that, but profiling
shows that Qt itself does not cache the value.

Part of reinvestigation of #12297.

src/frontends/qt/GuiFontMetrics.cpp
src/frontends/qt/GuiFontMetrics.h

index e7dab1e3e8cd7b9d61c966946a3b4feef9414736..0e69ffd998d09dafeb16240ead15c8c013455a80 100644 (file)
@@ -117,7 +117,7 @@ inline QChar const ucs4_to_qchar(char_type const ucs4)
 
 
 GuiFontMetrics::GuiFontMetrics(QFont const & font)
-       : font_(font), metrics_(font, 0),
+       : font_(font), metrics_(font, 0), xheight_(metrics_.xHeight()),
          strwidth_cache_(strwidth_cache_max_cost),
          breakstr_cache_(breakstr_cache_max_cost),
          qtextlayout_cache_(qtextlayout_cache_max_size)
@@ -167,7 +167,7 @@ int GuiFontMetrics::em() const
 int GuiFontMetrics::xHeight() const
 {
 //     LATTEST(metrics_.xHeight() == ascent('x'));
-       return metrics_.xHeight();
+       return xheight_;
 }
 
 
index 5c32ea9de89237cc9e6822ff50b1cb4ed84c86b9..5f73172c0d246f16c4c5b2a6ae7994fbca337800 100644 (file)
@@ -116,6 +116,9 @@ private:
        /// Metrics on the font
        QFontMetrics metrics_;
 
+       /// Height of character "x"
+       int xheight_;
+
        /// Slope of italic font
        double slope_;