[LyX/master] Cache the value of FontMetrics::xHeight()

Jean-Marc Lasgouttes lasgouttes at lyx.org
Sat Jul 15 20:34:11 UTC 2023


commit 386a2ddca135da7c96a4565a2648acf06394b5cc
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Sat Jul 15 19:39:14 2023 +0200

    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 e7dab1e..0e69ffd 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 5c32ea9..5f73172 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_;
 


More information about the lyx-cvs mailing list