diff -r 336bee5c2d35 -r dd58c6eee052 fontservices/fontstore/src/OPENFONT.CPP --- a/fontservices/fontstore/src/OPENFONT.CPP Wed Sep 01 12:39:40 2010 +0100 +++ b/fontservices/fontstore/src/OPENFONT.CPP Wed Sep 15 00:39:40 2010 +0300 @@ -26,6 +26,7 @@ #include "linkedfontsprivate.h" #include #include +#include const TInt KSessionCacheEntries = 512; const TInt KDefaultSlantFactor = 20480; @@ -848,13 +849,13 @@ iFileOffset = 0; } -COpenFontGlyphCache* COpenFont::GetGlyphCache() +COpenFontGlyphCache* COpenFont::GetGlyphCache() const { if (iGlyphCacheOffset == 0) { return NULL; } - return reinterpret_cast(PtrAdd(this, iGlyphCacheOffset)); + return reinterpret_cast(PtrAdd(const_cast(this), iGlyphCacheOffset)); } const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const @@ -893,7 +894,7 @@ @param aCode The code for the glpyh to look for in the cache @return A pointer to the requested glyph if it was found in the glyph cache, NULL if it was not found. */ -const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) +const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) const { if (COpenFontGlyphCache* glyphCache = GetGlyphCache()) { @@ -1056,58 +1057,52 @@ iEntryArray.Close(aHeap); } -const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) +const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) const { aIndex = -1; - TInt oldest = KMaxTInt; - TInt oldest_index = 0; TInt numEntries = iEntryArray.Count(); TInt index = GLYPH_CODE(aCode) % numEntries; // simple hash function to shorten searches for (TInt i = 0; i < numEntries; ++i, ++index) { if (index >= numEntries) + { index = 0; - COpenFontSessionCacheEntry* entry = iEntryArray[index]; + } + const COpenFontSessionCacheEntry* entry = iEntryArray[index]; if (entry == NULL) { - if (aIndex == -1) - aIndex = index; - } - else - { - if (entry->Font() == aFont && entry->iCode == aCode) + if (aIndex < 0) { - entry->iLastAccess = iLastAccess++; - return entry; - } - if (entry->iLastAccess < oldest) - { - oldest = entry->iLastAccess; - oldest_index = index; + aIndex = index; } } + else if (entry->Font() == aFont && entry->iCode == aCode) + { + return entry; + } } - if (aIndex == -1) - aIndex = oldest_index; return NULL; } void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex) { - if (aIndex < 0 || aIndex >= iEntryArray.Count()) + if (aIndex >= iEntryArray.Count()) { Panic(EFntSessionCacheIndexOutOfRange); } + if (aIndex < 0) + { + aIndex = Math::Rand(iRandomSeed) % iEntryArray.Count(); + } COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]); iEntryArray.SetAt(aIndex, aEntry); - aEntry->iLastAccess = iLastAccess++; } COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle): iSessionHandle(aSessionHandle), - iLastAccess(0) - { + iRandomSeed(0) + { } TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache)