From 386a2ddca135da7c96a4565a2648acf06394b5cc Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sat, 15 Jul 2023 19:39:14 +0200 Subject: [PATCH] Cache the value of FontMetrics::xHeight() 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 | 4 ++-- src/frontends/qt/GuiFontMetrics.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/frontends/qt/GuiFontMetrics.cpp b/src/frontends/qt/GuiFontMetrics.cpp index e7dab1e3e8..0e69ffd998 100644 --- a/src/frontends/qt/GuiFontMetrics.cpp +++ b/src/frontends/qt/GuiFontMetrics.cpp @@ -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_; } diff --git a/src/frontends/qt/GuiFontMetrics.h b/src/frontends/qt/GuiFontMetrics.h index 5c32ea9de8..5f73172c0d 100644 --- a/src/frontends/qt/GuiFontMetrics.h +++ b/src/frontends/qt/GuiFontMetrics.h @@ -116,6 +116,9 @@ private: /// Metrics on the font QFontMetrics metrics_; + /// Height of character "x" + int xheight_; + /// Slope of italic font double slope_; -- 2.39.5