The attached patch implements caching of the rbearing values as they are
now used in mathed when positioning superscripts. Without this patch, on
Windows the dreaded csrss.exe thing comes back eating cpu cycles and
scrolling with lots of math is noticeably slowed down.

I plan to commit it later tonight unless I get objections.

-- 
Enrico
Index: src/frontends/qt4/GuiFontMetrics.h
===================================================================
--- src/frontends/qt4/GuiFontMetrics.h  (revision 17496)
+++ src/frontends/qt4/GuiFontMetrics.h  (working copy)
@@ -75,6 +75,9 @@ private:
        mutable QHash<char_type, AscendDescend> metrics_cache_;
        /// fill in \c metrics_cache_ at specified value.
        void fillMetricsCache(char_type) const;
+
+       /// Cache of char right bearings
+       mutable QHash<char_type, int> rbearing_cache_;
 };
 
 } // namespace frontend
Index: src/frontends/qt4/GuiFontMetrics.C
===================================================================
--- src/frontends/qt4/GuiFontMetrics.C  (revision 17496)
+++ src/frontends/qt4/GuiFontMetrics.C  (working copy)
@@ -59,9 +59,13 @@ int GuiFontMetrics::lbearing(char_type c
 
 int GuiFontMetrics::rbearing(char_type c) const
 {
-       // Qt rbearing is from the right edge of the char's width().
-       QChar sc = ucs4_to_qchar(c);
-       return metrics_.width(sc) - metrics_.rightBearing(sc);
+       if (!rbearing_cache_.contains(c)) {
+               // Qt rbearing is from the right edge of the char's width().
+               QChar sc = ucs4_to_qchar(c);
+               int rb = metrics_.width(sc) - metrics_.rightBearing(sc);
+               rbearing_cache_.insert(c, rb);
+       }
+       return rbearing_cache_.value(c);
 }
 
 

Reply via email to