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.
This commit is contained in:
Jean-Marc Lasgouttes 2023-07-15 19:39:14 +02:00
parent d8e509e5eb
commit 386a2ddca1
2 changed files with 5 additions and 2 deletions

View 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_;
}

View File

@ -116,6 +116,9 @@ private:
/// Metrics on the font
QFontMetrics metrics_;
/// Height of character "x"
int xheight_;
/// Slope of italic font
double slope_;