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)
: 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
int GuiFontMetrics::width(unsigned short val) const
{
GuiFontMetrics::WidthCache::const_iterator cit = widthcache.find(val);
if (cit != widthcache.end())
return cit->second;
int const w = metrics_.width(QChar(val));
widthcache[val] = w;
return w;
if (widthcache_[val] == -1)
widthcache_[val] = metrics_.width(QChar(val));
return widthcache_[val];
}
#endif

View File

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