replace the map based width cache with an array based one.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15585 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-10-27 22:46:36 +00:00
parent 7f94f08bbe
commit 1372f311d3
2 changed files with 8 additions and 9 deletions

View File

@ -31,6 +31,10 @@ namespace frontend {
GuiFontMetrics::GuiFontMetrics(QFont const & font) GuiFontMetrics::GuiFontMetrics(QFont const & font)
: metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false) : metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false)
{ {
#ifdef USE_LYX_FONTCACHE
for (int i = 0; i != 65536; ++i)
widthcache_[i] = -1;
#endif
} }
@ -184,13 +188,9 @@ void GuiFontMetrics::buttonText(docstring const & str,
#ifdef USE_LYX_FONTCACHE #ifdef USE_LYX_FONTCACHE
int GuiFontMetrics::width(unsigned short val) const int GuiFontMetrics::width(unsigned short val) const
{ {
GuiFontMetrics::WidthCache::const_iterator cit = widthcache.find(val); if (widthcache_[val] == -1)
if (cit != widthcache.end()) widthcache_[val] = metrics_.width(QChar(val));
return cit->second; return widthcache_[val];
int const w = metrics_.width(QChar(val));
widthcache[val] = w;
return w;
} }
#endif #endif

View File

@ -73,9 +73,8 @@ private:
/// Return pixel width for the given unicode char /// Return pixel width for the given unicode char
int width(unsigned short val) const; int width(unsigned short val) const;
typedef std::map<unsigned short, int> WidthCache;
/// Cache of char widths /// Cache of char widths
mutable WidthCache widthcache; mutable int widthcache_[65536];
#endif // USE_LYX_FONTCACHE #endif // USE_LYX_FONTCACHE
}; };