#ifndef WidthCache_h
#define WidthCache_h
+#include "platform/geometry/IntRectExtent.h"
#include "platform/text/TextRun.h"
#include "wtf/Forward.h"
#include "wtf/HashFunctions.h"
#include "wtf/HashTableDeletedValueType.h"
#include "wtf/StringHasher.h"
-namespace WebCore {
+namespace blink {
struct GlyphOverflow;
+struct WidthCacheEntry {
+ WidthCacheEntry()
+ {
+ width = std::numeric_limits<float>::quiet_NaN();
+ }
+ bool isValid() const { return !std::isnan(width); }
+ float width;
+ IntRectExtent glyphBounds;
+};
+
class WidthCache {
private:
// Used to optimize small strings as hash table keys. Avoids malloc'ing an out-of-line StringImpl.
{
}
- float* add(const TextRun& run, float entry)
+ WidthCacheEntry* add(const TextRun& run, WidthCacheEntry entry)
{
if (static_cast<unsigned>(run.length()) > SmallStringKey::capacity())
return 0;
}
private:
- float* addSlowCase(const TextRun& run, float entry)
+ WidthCacheEntry* addSlowCase(const TextRun& run, WidthCacheEntry entry)
{
int length = run.length();
bool isNewEntry;
- float *value;
+ WidthCacheEntry *value;
if (length == 1) {
SingleCharMap::AddResult addResult = m_singleCharMap.add(run[0], entry);
isNewEntry = addResult.isNewEntry;
return 0;
}
- typedef HashMap<SmallStringKey, float, SmallStringKeyHash, SmallStringKeyHashTraits> Map;
- typedef HashMap<uint32_t, float, DefaultHash<uint32_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint32_t> > SingleCharMap;
+ typedef HashMap<SmallStringKey, WidthCacheEntry, SmallStringKeyHash, SmallStringKeyHashTraits> Map;
+ typedef HashMap<uint32_t, WidthCacheEntry, DefaultHash<uint32_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint32_t> > SingleCharMap;
static const int s_minInterval = -3; // A cache hit pays for about 3 cache misses.
static const int s_maxInterval = 20; // Sampling at this interval has almost no overhead.
static const unsigned s_maxSize = 500000; // Just enough to guard against pathological growth.
return WTF::equal(a.characters(), b.characters(), a.length());
}
-} // namespace WebCore
+} // namespace blink
#endif // WidthCache_h