RESOLVED FIXED 147751
Make FontDescriptionKey sensitive to FontFeatureSettings
https://bugs.webkit.org/show_bug.cgi?id=147751
Summary Make FontDescriptionKey sensitive to FontFeatureSettings
Myles C. Maxfield
Reported 2015-08-06 15:24:10 PDT
Make FontDescriptionKey sensitive to FontFeatureSettings
Attachments
Patch (8.91 KB, patch)
2015-08-06 15:26 PDT, Myles C. Maxfield
no flags
Patch (8.91 KB, patch)
2015-08-06 15:33 PDT, Myles C. Maxfield
no flags
Patch (8.54 KB, patch)
2015-08-06 15:54 PDT, Myles C. Maxfield
no flags
Patch (8.58 KB, patch)
2015-08-06 15:57 PDT, Myles C. Maxfield
no flags
Patch (8.66 KB, patch)
2015-08-06 16:02 PDT, Myles C. Maxfield
andersca: review+
Myles C. Maxfield
Comment 1 2015-08-06 15:26:01 PDT
Myles C. Maxfield
Comment 2 2015-08-06 15:33:10 PDT
Myles C. Maxfield
Comment 3 2015-08-06 15:34:40 PDT
Comment on attachment 258408 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258408&action=review > Source/WebCore/ChangeLog:14 > + I should probably also say that this patch is in preparation for implementing font-feature-settings.
Sam Weinig
Comment 4 2015-08-06 15:34:55 PDT
Comment on attachment 258407 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258407&action=review > Source/WebCore/platform/graphics/FontCache.h:75 > + , m_featureSettings(0) Is this needed? m_featureSettings will be default contracted to null. > Source/WebCore/platform/graphics/FontCache.h:132 > + unsigned m_size; > + unsigned m_weight; > + unsigned m_flags; Can we default these to 0 here? > Source/WebCore/platform/graphics/FontFeatureSettings.cpp:72 > + unsigned result = 0x5E787623U; // Chosen randomly Why do we need a random number?
Sam Weinig
Comment 5 2015-08-06 15:39:21 PDT
Comment on attachment 258408 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258408&action=review > Source/WebCore/platform/graphics/FontCache.h:110 > + unsigned result = WTF::intHash(m_size); > + result = WTF::pairIntHash(result, WTF::intHash(m_weight)); > + result = WTF::pairIntHash(result, WTF::intHash(m_flags)); > + result = WTF::pairIntHash(result, WTF::intHash(m_flags)); > + result = WTF::PairHash<AtomicString, unsigned>::hash(std::make_pair(m_locale, result)); > + result = WTF::pairIntHash(result, m_featureSettings ? m_featureSettings->hash() : 0); The way we usually do this to create an array of unsigned and pass it to StringHasher::hashMemory. See SecurityOriginHash.h for an example. We really need to add a hash_combine like thing (http://www.boost.org/doc/libs/1_55_0/doc/html/hash/combine.html).
Blaze Burg
Comment 6 2015-08-06 15:41:48 PDT
Comment on attachment 258408 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258408&action=review > Source/WebCore/platform/graphics/FontCache.h:72 > + : m_size(0) What about > Source/WebCore/platform/graphics/FontCache.h:131 > + unsigned m_weight; You could initialize these like so: unsigned m_size {0}; and remove the default constructor entirely.
Myles C. Maxfield
Comment 7 2015-08-06 15:42:19 PDT
Comment on attachment 258408 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258408&action=review >> Source/WebCore/platform/graphics/FontCache.h:110 >> + result = WTF::pairIntHash(result, m_featureSettings ? m_featureSettings->hash() : 0); > > The way we usually do this to create an array of unsigned and pass it to StringHasher::hashMemory. See SecurityOriginHash.h for an example. We really need to add a hash_combine like thing (http://www.boost.org/doc/libs/1_55_0/doc/html/hash/combine.html). Ah, yes, I've seen that pattern in PlatformFontData. I'll use that.
Myles C. Maxfield
Comment 8 2015-08-06 15:44:47 PDT
Comment on attachment 258407 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258407&action=review >> Source/WebCore/platform/graphics/FontCache.h:75 >> + , m_featureSettings(0) > > Is this needed? m_featureSettings will be default contracted to null. Nope! >> Source/WebCore/platform/graphics/FontCache.h:132 >> + unsigned m_flags; > > Can we default these to 0 here? Yep! >> Source/WebCore/platform/graphics/FontFeatureSettings.cpp:72 >> + unsigned result = 0x5E787623U; // Chosen randomly > > Why do we need a random number? Because this is the input to a hash function, it seems like a better idea than just 0 for increasing entropy.
Myles C. Maxfield
Comment 9 2015-08-06 15:47:26 PDT
Comment on attachment 258408 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258408&action=review > Source/WebCore/platform/graphics/FontCache.h:109 > + result = WTF::pairIntHash(result, WTF::intHash(m_flags)); > + result = WTF::pairIntHash(result, WTF::intHash(m_flags)); > + result = WTF::PairHash<AtomicString, unsigned>::hash(std::make_pair(m_locale, result)); Wow, I completely messed this up
Myles C. Maxfield
Comment 10 2015-08-06 15:54:22 PDT
Myles C. Maxfield
Comment 11 2015-08-06 15:57:31 PDT
Myles C. Maxfield
Comment 12 2015-08-06 16:02:50 PDT
Myles C. Maxfield
Comment 13 2015-08-06 16:32:25 PDT
Darin Adler
Comment 14 2015-08-08 14:49:57 PDT
Comment on attachment 258412 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258412&action=review > Source/WebCore/platform/graphics/FontFeatureSettings.cpp:75 > + unsigned result = 0; > + for (size_t i = 0; i < size(); ++i) > + result = WTF::pairIntHash(result, at(i).hash()); > + return result; Is this really a good way to hash a vector? I think there’s a better approach where we accumulate with a single hash rather than hashing the old hash with a new hash value every time. Likely more efficient as well. There must be some good example elsewhere where we do this.
Darin Adler
Comment 15 2015-08-08 14:50:51 PDT
Comment on attachment 258412 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=258412&action=review >> Source/WebCore/platform/graphics/FontFeatureSettings.cpp:75 >> + return result; > > Is this really a good way to hash a vector? I think there’s a better approach where we accumulate with a single hash rather than hashing the old hash with a new hash value every time. Likely more efficient as well. There must be some good example elsewhere where we do this. Hmm, I see you discussing this with Sam earlier, but I am not really sure about where you ended up here. I’d like to understand so I can do it right in the future.
Myles C. Maxfield
Comment 16 2015-08-10 21:01:53 PDT
(In reply to comment #15) > Comment on attachment 258412 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=258412&action=review > > >> Source/WebCore/platform/graphics/FontFeatureSettings.cpp:75 > >> + return result; > > > > Is this really a good way to hash a vector? I think there’s a better approach where we accumulate with a single hash rather than hashing the old hash with a new hash value every time. Likely more efficient as well. There must be some good example elsewhere where we do this. > > Hmm, I see you discussing this with Sam earlier, but I am not really sure > about where you ended up here. I’d like to understand so I can do it right > in the future. It looks like StringHasher has an interface where you can push data into it willy-nilly. I'll use that.
Myles C. Maxfield
Comment 17 2015-08-10 21:27:26 PDT
(In reply to comment #16) > (In reply to comment #15) > > Comment on attachment 258412 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=258412&action=review > > > > >> Source/WebCore/platform/graphics/FontFeatureSettings.cpp:75 > > >> + return result; > > > > > > Is this really a good way to hash a vector? I think there’s a better approach where we accumulate with a single hash rather than hashing the old hash with a new hash value every time. Likely more efficient as well. There must be some good example elsewhere where we do this. > > > > Hmm, I see you discussing this with Sam earlier, but I am not really sure > > about where you ended up here. I’d like to understand so I can do it right > > in the future. > > It looks like StringHasher has an interface where you can push data into it > willy-nilly. I'll use that. https://bugs.webkit.org/show_bug.cgi?id=147866
Note You need to log in before you can comment on or make changes to this bug.