| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2015 Google Inc. All rights reserved. | 3 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 46 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 47 ShapeCacheEntry() { m_shapeResult = nullptr; } | 47 ShapeCacheEntry() { m_shapeResult = nullptr; } |
| 48 RefPtr<const ShapeResult> m_shapeResult; | 48 RefPtr<const ShapeResult> m_shapeResult; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 class ShapeCache { | 51 class ShapeCache { |
| 52 USING_FAST_MALLOC(ShapeCache); | 52 USING_FAST_MALLOC(ShapeCache); |
| 53 WTF_MAKE_NONCOPYABLE(ShapeCache); | 53 WTF_MAKE_NONCOPYABLE(ShapeCache); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // Used to optimize small strings as hash table keys. Avoids malloc'ing an out
-of-line StringImpl. | 56 // Used to optimize small strings as hash table keys. Avoids malloc'ing an |
| 57 // out-of-line StringImpl. |
| 57 class SmallStringKey { | 58 class SmallStringKey { |
| 58 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 59 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 59 | 60 |
| 60 public: | 61 public: |
| 61 static unsigned capacity() { return s_capacity; } | 62 static unsigned capacity() { return s_capacity; } |
| 62 | 63 |
| 63 SmallStringKey() : m_length(s_emptyValueLength), m_direction(LTR) {} | 64 SmallStringKey() : m_length(s_emptyValueLength), m_direction(LTR) {} |
| 64 | 65 |
| 65 SmallStringKey(WTF::HashTableDeletedValueType) | 66 SmallStringKey(WTF::HashTableDeletedValueType) |
| 66 : m_length(s_deletedValueLength), m_direction(LTR) {} | 67 : m_length(s_deletedValueLength), m_direction(LTR) {} |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 unsigned m_direction : 1; | 118 unsigned m_direction : 1; |
| 118 UChar m_characters[s_capacity]; | 119 UChar m_characters[s_capacity]; |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 struct SmallStringKeyHash { | 122 struct SmallStringKeyHash { |
| 122 STATIC_ONLY(SmallStringKeyHash); | 123 STATIC_ONLY(SmallStringKeyHash); |
| 123 static unsigned hash(const SmallStringKey& key) { return key.hash(); } | 124 static unsigned hash(const SmallStringKey& key) { return key.hash(); } |
| 124 static bool equal(const SmallStringKey& a, const SmallStringKey& b) { | 125 static bool equal(const SmallStringKey& a, const SmallStringKey& b) { |
| 125 return a == b; | 126 return a == b; |
| 126 } | 127 } |
| 127 static const bool safeToCompareToEmptyOrDeleted = | 128 // Empty and deleted values have lengths that are not equal to any valid |
| 128 true; // Empty and deleted values have lengths that are not equal to an
y valid length. | 129 // length. |
| 130 static const bool safeToCompareToEmptyOrDeleted = true; |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 struct SmallStringKeyHashTraits : WTF::SimpleClassHashTraits<SmallStringKey> { | 133 struct SmallStringKeyHashTraits : WTF::SimpleClassHashTraits<SmallStringKey> { |
| 132 STATIC_ONLY(SmallStringKeyHashTraits); | 134 STATIC_ONLY(SmallStringKeyHashTraits); |
| 133 static const bool hasIsEmptyValueFunction = true; | 135 static const bool hasIsEmptyValueFunction = true; |
| 134 static bool isEmptyValue(const SmallStringKey& key) { | 136 static bool isEmptyValue(const SmallStringKey& key) { |
| 135 return key.isHashTableEmptyValue(); | 137 return key.isHashTableEmptyValue(); |
| 136 } | 138 } |
| 137 static const unsigned minimumTableSize = 16; | 139 static const unsigned minimumTableSize = 16; |
| 138 }; | 140 }; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 inline bool operator==(const ShapeCache::SmallStringKey& a, | 251 inline bool operator==(const ShapeCache::SmallStringKey& a, |
| 250 const ShapeCache::SmallStringKey& b) { | 252 const ShapeCache::SmallStringKey& b) { |
| 251 if (a.length() != b.length() || a.direction() != b.direction()) | 253 if (a.length() != b.length() || a.direction() != b.direction()) |
| 252 return false; | 254 return false; |
| 253 return WTF::equal(a.characters(), b.characters(), a.length()); | 255 return WTF::equal(a.characters(), b.characters(), a.length()); |
| 254 } | 256 } |
| 255 | 257 |
| 256 } // namespace blink | 258 } // namespace blink |
| 257 | 259 |
| 258 #endif // ShapeCache_h | 260 #endif // ShapeCache_h |
| OLD | NEW |