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 static inline void addToHash(unsigned& hash, unsigned key) { |
| 14 hash = ((hash << 5) + hash) + key; // Djb2 |
| 15 }; |
| 16 |
| 17 static inline void addFloatToHash(unsigned& hash, float value) { |
| 18 addToHash(hash, StringHasher::hashMemory(&value, sizeof(value))); |
| 19 }; |
| 20 |
| 21 unsigned FontVariationSettings::hash() const { |
| 22 unsigned computedHash = size() ? 5381 : 0; |
| 23 unsigned numFeatures = size(); |
| 24 for (unsigned i = 0; i < numFeatures; ++i) { |
| 25 StringHasher stringHasher; |
| 26 const AtomicString& tag = at(i).tag(); |
| 27 for (unsigned j = 0; j < tag.length(); j++) { |
| 28 stringHasher.addCharacter(tag[j]); |
| 29 } |
| 30 addToHash(computedHash, stringHasher.hash()); |
| 31 addFloatToHash(computedHash, at(i).value()); |
| 32 } |
| 33 return computedHash; |
| 34 } |
| 35 |
| 36 } // namespace blink |
OLD | NEW |