- Revision
- 188088
- Author
- mmaxfi...@apple.com
- Date
- 2015-08-06 16:31:53 -0700 (Thu, 06 Aug 2015)
Log Message
Make FontDescriptionKey sensitive to FontFeatureSettings
https://bugs.webkit.org/show_bug.cgi?id=147751
Reviewed by Anders Carlsson.
Just like how FontDescription hashes should be sensitive to locale, they should
also be sensitive to font features.
This patch also fixes operator== for FontDescriptionKey, which was previously
comparing hashes for equality instead of the underlying data. Comparing hashes
for equality is useless inside hashmaps.
This is in preparation for implementing font-feature-settings.
No new tests because there is no behavior change.
* platform/graphics/FontCache.cpp:
(WebCore::FontPlatformDataCacheKey::FontPlatformDataCacheKey):
(WebCore::FontPlatformDataCacheKey::isHashTableDeletedValue):
(WebCore::FontPlatformDataCacheKey::hashTableDeletedSize): Deleted.
* platform/graphics/FontCache.h:
(WebCore::FontDescriptionKey::FontDescriptionKey):
(WebCore::FontDescriptionKey::operator==):
(WebCore::FontDescriptionKey::operator!=):
(WebCore::FontDescriptionKey::isHashTableDeletedValue):
(WebCore::FontDescriptionKey::computeHash):
* platform/graphics/FontFeatureSettings.cpp:
(WebCore::FontFeature::hash):
(WebCore::FontFeatureSettings::hash):
* platform/graphics/FontFeatureSettings.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (188087 => 188088)
--- trunk/Source/WebCore/ChangeLog 2015-08-06 23:31:45 UTC (rev 188087)
+++ trunk/Source/WebCore/ChangeLog 2015-08-06 23:31:53 UTC (rev 188088)
@@ -1,3 +1,36 @@
+2015-08-06 Myles C. Maxfield <mmaxfi...@apple.com>
+
+ Make FontDescriptionKey sensitive to FontFeatureSettings
+ https://bugs.webkit.org/show_bug.cgi?id=147751
+
+ Reviewed by Anders Carlsson.
+
+ Just like how FontDescription hashes should be sensitive to locale, they should
+ also be sensitive to font features.
+
+ This patch also fixes operator== for FontDescriptionKey, which was previously
+ comparing hashes for equality instead of the underlying data. Comparing hashes
+ for equality is useless inside hashmaps.
+
+ This is in preparation for implementing font-feature-settings.
+
+ No new tests because there is no behavior change.
+
+ * platform/graphics/FontCache.cpp:
+ (WebCore::FontPlatformDataCacheKey::FontPlatformDataCacheKey):
+ (WebCore::FontPlatformDataCacheKey::isHashTableDeletedValue):
+ (WebCore::FontPlatformDataCacheKey::hashTableDeletedSize): Deleted.
+ * platform/graphics/FontCache.h:
+ (WebCore::FontDescriptionKey::FontDescriptionKey):
+ (WebCore::FontDescriptionKey::operator==):
+ (WebCore::FontDescriptionKey::operator!=):
+ (WebCore::FontDescriptionKey::isHashTableDeletedValue):
+ (WebCore::FontDescriptionKey::computeHash):
+ * platform/graphics/FontFeatureSettings.cpp:
+ (WebCore::FontFeature::hash):
+ (WebCore::FontFeatureSettings::hash):
+ * platform/graphics/FontFeatureSettings.h:
+
2015-08-06 Anders Carlsson <ander...@apple.com>
Merge SQLStatement into SQLStatementBackend
Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (188087 => 188088)
--- trunk/Source/WebCore/platform/graphics/FontCache.cpp 2015-08-06 23:31:45 UTC (rev 188087)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp 2015-08-06 23:31:53 UTC (rev 188088)
@@ -105,9 +105,12 @@
, m_family(family)
{ }
- FontPlatformDataCacheKey(HashTableDeletedValueType) : m_fontDescriptionKey(hashTableDeletedSize()) { }
- bool isHashTableDeletedValue() const { return m_fontDescriptionKey.size == hashTableDeletedSize(); }
+ explicit FontPlatformDataCacheKey(HashTableDeletedValueType t)
+ : m_fontDescriptionKey(t)
+ { }
+ bool isHashTableDeletedValue() const { return m_fontDescriptionKey.isHashTableDeletedValue(); }
+
bool operator==(const FontPlatformDataCacheKey& other) const
{
return equalIgnoringCase(m_family, other.m_family) && m_fontDescriptionKey == other.m_fontDescriptionKey;
@@ -115,9 +118,6 @@
FontDescriptionKey m_fontDescriptionKey;
AtomicString m_family;
-
-private:
- static unsigned hashTableDeletedSize() { return 0xFFFFFFFFU; }
};
struct FontPlatformDataCacheKeyHash {
Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (188087 => 188088)
--- trunk/Source/WebCore/platform/graphics/FontCache.h 2015-08-06 23:31:45 UTC (rev 188087)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h 2015-08-06 23:31:53 UTC (rev 188088)
@@ -37,6 +37,7 @@
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
+#include <wtf/text/AtomicStringHash.h>
#include <wtf/text/WTFString.h>
#if PLATFORM(IOS)
@@ -67,18 +68,40 @@
// This key contains the FontDescription fields other than family that matter when fetching FontDatas (platform fonts).
struct FontDescriptionKey {
- explicit FontDescriptionKey(unsigned size = 0)
- : size(size)
- , weight(0)
- , flags(0)
- , localeHash(0)
- { }
+ FontDescriptionKey() = default;
+
FontDescriptionKey(const FontDescription& description)
- : size(description.computedPixelSize())
- , weight(description.weight())
- , flags(makeFlagKey(description))
- , localeHash(description.locale().isNull() ? 0 : description.locale().impl()->existingHash())
+ : m_size(description.computedPixelSize())
+ , m_weight(description.weight())
+ , m_flags(makeFlagKey(description))
+ , m_locale(description.locale())
+ , m_featureSettings(description.featureSettings())
{ }
+
+ explicit FontDescriptionKey(WTF::HashTableDeletedValueType)
+ : m_size(cHashTableDeletedSize)
+ { }
+
+ bool operator==(const FontDescriptionKey& other) const
+ {
+ return m_size == other.m_size && m_weight == other.m_weight && m_flags == other.m_flags && m_locale == other.m_locale
+ && ((m_featureSettings == other.m_featureSettings) || (m_featureSettings && other.m_featureSettings && m_featureSettings.get() == other.m_featureSettings.get()));
+ }
+
+ bool operator!=(const FontDescriptionKey& other) const
+ {
+ return !(*this == other);
+ }
+
+ bool isHashTableDeletedValue() const { return m_size == cHashTableDeletedSize; }
+
+ inline unsigned computeHash() const
+ {
+ unsigned toHash[] = {m_size, m_weight, m_flags, m_locale.isNull() ? 0 : m_locale.impl()->existingHash(), m_featureSettings ? m_featureSettings->hash() : 0};
+ return StringHasher::hashMemory(toHash, sizeof(toHash));
+ }
+
+private:
static unsigned makeFlagKey(const FontDescription& description)
{
static_assert(USCRIPT_CODE_LIMIT < 0x1000, "Script code must fit in an unsigned along with the other flags");
@@ -91,22 +114,14 @@
| static_cast<unsigned>(description.italic()) << 1
| static_cast<unsigned>(description.renderingMode());
}
- bool operator==(const FontDescriptionKey& other) const
- {
- return size == other.size && weight == other.weight && flags == other.flags && localeHash == other.localeHash;
- }
- bool operator!=(const FontDescriptionKey& other) const
- {
- return !(*this == other);
- }
- inline unsigned computeHash() const
- {
- return StringHasher::hashMemory<sizeof(FontDescriptionKey)>(this);
- }
- unsigned size;
- unsigned weight;
- unsigned flags;
- unsigned localeHash; // FIXME: Here, and every client of us, makes hashes of hashes.
+
+ static const unsigned cHashTableDeletedSize = 0xFFFFFFFFU;
+
+ unsigned m_size { 0 };
+ unsigned m_weight { 0 };
+ unsigned m_flags { 0 };
+ AtomicString m_locale;
+ RefPtr<FontFeatureSettings> m_featureSettings;
};
class FontCache {
Modified: trunk/Source/WebCore/platform/graphics/FontFeatureSettings.cpp (188087 => 188088)
--- trunk/Source/WebCore/platform/graphics/FontFeatureSettings.cpp 2015-08-06 23:31:45 UTC (rev 188087)
+++ trunk/Source/WebCore/platform/graphics/FontFeatureSettings.cpp 2015-08-06 23:31:53 UTC (rev 188088)
@@ -26,6 +26,8 @@
#include "config.h"
#include "FontFeatureSettings.h"
+#include <wtf/text/AtomicStringHash.h>
+
namespace WebCore {
FontFeature::FontFeature(const AtomicString& tag, int value)
@@ -44,6 +46,11 @@
return (m_tag.impl() < other.m_tag.impl()) || (m_tag.impl() == other.m_tag.impl() && m_value < other.m_value);
}
+unsigned FontFeature::hash() const
+{
+ return WTF::PairHash<AtomicString, unsigned>::hash(std::make_pair(m_tag, m_value));
+}
+
Ref<FontFeatureSettings> FontFeatureSettings::create()
{
return adoptRef(*new FontFeatureSettings);
@@ -60,4 +67,12 @@
m_list.insert(i, WTF::move(feature));
}
+unsigned FontFeatureSettings::hash() const
+{
+ unsigned result = 0;
+ for (size_t i = 0; i < size(); ++i)
+ result = WTF::pairIntHash(result, at(i).hash());
+ return result;
}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/FontFeatureSettings.h (188087 => 188088)
--- trunk/Source/WebCore/platform/graphics/FontFeatureSettings.h 2015-08-06 23:31:45 UTC (rev 188087)
+++ trunk/Source/WebCore/platform/graphics/FontFeatureSettings.h 2015-08-06 23:31:53 UTC (rev 188088)
@@ -44,6 +44,8 @@
const AtomicString& tag() const { return m_tag; }
int value() const { return m_value; }
+ unsigned hash() const;
+
private:
AtomicString m_tag;
const int m_value { 0 };
@@ -59,6 +61,8 @@
const FontFeature& operator[](int index) const { return m_list[index]; }
const FontFeature& at(size_t index) const { return m_list.at(index); }
+ unsigned hash() const;
+
private:
FontFeatureSettings() { }
Vector<FontFeature> m_list;