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/HashFunctions.h" |
| 8 #include "wtf/StringHasher.h" |
| 9 #include "wtf/text/AtomicStringHash.h" |
| 10 #include "wtf/text/StringHash.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 uint32_t atomicStringToFourByteTag(AtomicString tag) { |
| 15 DCHECK_EQ(tag.length(), 4u); |
| 16 return (((tag[0]) << 24) | ((tag[1]) << 16) | ((tag[2]) << 8) | (tag[3])); |
| 17 } |
| 18 |
| 19 static inline void addToHash(unsigned& hash, unsigned key) { |
| 20 hash = ((hash << 5) + hash) + key; // Djb2 |
| 21 }; |
| 22 |
| 23 static inline void addFloatToHash(unsigned& hash, float value) { |
| 24 addToHash(hash, WTF::FloatHash<float>::hash(value)); |
| 25 }; |
| 26 |
| 27 unsigned FontVariationSettings::hash() const { |
| 28 unsigned computedHash = size() ? 5381 : 0; |
| 29 unsigned numFeatures = size(); |
| 30 for (unsigned i = 0; i < numFeatures; ++i) { |
| 31 StringHasher stringHasher; |
| 32 const AtomicString& tag = at(i).tag(); |
| 33 for (unsigned j = 0; j < tag.length(); j++) { |
| 34 stringHasher.addCharacter(tag[j]); |
| 35 } |
| 36 addToHash(computedHash, stringHasher.hash()); |
| 37 addFloatToHash(computedHash, at(i).value()); |
| 38 } |
| 39 return computedHash; |
| 40 } |
| 41 |
| 42 } // namespace blink |
OLD | NEW |