OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "platform/fonts/opentype/FontSettings.h" | |
6 | |
7 #include "wtf/StringHasher.h" | |
8 #include "wtf/text/AtomicStringHash.h" | |
9 #include "wtf/text/StringHash.h" | |
10 | |
11 namespace blink { | |
12 | |
13 uint32_t atomicStringToFourByteTag(AtomicString tag) { | |
14 DCHECK_EQ(tag.length(), 4u); | |
15 return (((tag[0]) << 24) | ((tag[1]) << 16) | ((tag[2]) << 8) | (tag[3])); | |
16 } | |
17 | |
18 static inline void addToHash(unsigned& hash, unsigned key) { | |
19 hash = ((hash << 5) + hash) + key; // Djb2 | |
20 }; | |
21 | |
22 static inline void addFloatToHash(unsigned& hash, float value) { | |
23 addToHash(hash, StringHasher::hashMemory(&value, sizeof(value))); | |
kojii
2016/12/21 14:53:12
Not important but just from curiosity, why don't w
drott
2016/12/21 15:22:00
Good point, took this from similar code in FontDes
| |
24 }; | |
25 | |
26 unsigned FontVariationSettings::hash() const { | |
27 unsigned computedHash = size() ? 5381 : 0; | |
28 unsigned numFeatures = size(); | |
29 for (unsigned i = 0; i < numFeatures; ++i) { | |
30 StringHasher stringHasher; | |
31 const AtomicString& tag = at(i).tag(); | |
32 for (unsigned j = 0; j < tag.length(); j++) { | |
33 stringHasher.addCharacter(tag[j]); | |
34 } | |
35 addToHash(computedHash, stringHasher.hash()); | |
36 addFloatToHash(computedHash, at(i).value()); | |
37 } | |
38 return computedHash; | |
39 } | |
40 | |
41 } // namespace blink | |
OLD | NEW |