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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 private: | 51 private: |
52 // Used to optimize small strings as hash table keys. Avoids malloc'ing an | 52 // Used to optimize small strings as hash table keys. Avoids malloc'ing an |
53 // out-of-line StringImpl. | 53 // out-of-line StringImpl. |
54 class SmallStringKey { | 54 class SmallStringKey { |
55 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 55 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
56 | 56 |
57 public: | 57 public: |
58 static unsigned capacity() { return s_capacity; } | 58 static unsigned capacity() { return s_capacity; } |
59 | 59 |
60 SmallStringKey() : m_length(s_emptyValueLength), m_direction(LTR) {} | 60 SmallStringKey() |
| 61 : m_length(s_emptyValueLength), |
| 62 m_direction(static_cast<unsigned>(TextDirection::Ltr)) {} |
61 | 63 |
62 SmallStringKey(WTF::HashTableDeletedValueType) | 64 SmallStringKey(WTF::HashTableDeletedValueType) |
63 : m_length(s_deletedValueLength), m_direction(LTR) {} | 65 : m_length(s_deletedValueLength), |
| 66 m_direction(static_cast<unsigned>(TextDirection::Ltr)) {} |
64 | 67 |
65 template <typename CharacterType> | 68 template <typename CharacterType> |
66 SmallStringKey(CharacterType* characters, | 69 SmallStringKey(CharacterType* characters, |
67 unsigned short length, | 70 unsigned short length, |
68 TextDirection direction) | 71 TextDirection direction) |
69 : m_length(length), m_direction(direction) { | 72 : m_length(length), m_direction(static_cast<unsigned>(direction)) { |
70 ASSERT(length <= s_capacity); | 73 ASSERT(length <= s_capacity); |
71 | 74 |
72 StringHasher hasher; | 75 StringHasher hasher; |
73 | 76 |
74 bool remainder = length & 1; | 77 bool remainder = length & 1; |
75 length >>= 1; | 78 length >>= 1; |
76 | 79 |
77 unsigned i = 0; | 80 unsigned i = 0; |
78 while (length--) { | 81 while (length--) { |
79 m_characters[i] = characters[i]; | 82 m_characters[i] = characters[i]; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 181 |
179 private: | 182 private: |
180 ShapeCacheEntry* addSlowCase(const TextRun& run, ShapeCacheEntry entry) { | 183 ShapeCacheEntry* addSlowCase(const TextRun& run, ShapeCacheEntry entry) { |
181 unsigned length = run.length(); | 184 unsigned length = run.length(); |
182 bool isNewEntry; | 185 bool isNewEntry; |
183 ShapeCacheEntry* value; | 186 ShapeCacheEntry* value; |
184 if (length == 1) { | 187 if (length == 1) { |
185 uint32_t key = run[0]; | 188 uint32_t key = run[0]; |
186 // All current codepointsin UTF-32 are bewteen 0x0 and 0x10FFFF, | 189 // All current codepointsin UTF-32 are bewteen 0x0 and 0x10FFFF, |
187 // as such use bit 32 to indicate direction. | 190 // as such use bit 32 to indicate direction. |
188 if (run.direction() == RTL) | 191 if (run.direction() == TextDirection::Rtl) |
189 key |= (1u << 31); | 192 key |= (1u << 31); |
190 SingleCharMap::AddResult addResult = m_singleCharMap.add(key, entry); | 193 SingleCharMap::AddResult addResult = m_singleCharMap.add(key, entry); |
191 isNewEntry = addResult.isNewEntry; | 194 isNewEntry = addResult.isNewEntry; |
192 value = &addResult.storedValue->value; | 195 value = &addResult.storedValue->value; |
193 } else { | 196 } else { |
194 SmallStringKey smallStringKey; | 197 SmallStringKey smallStringKey; |
195 if (run.is8Bit()) | 198 if (run.is8Bit()) |
196 smallStringKey = | 199 smallStringKey = |
197 SmallStringKey(run.characters8(), length, run.direction()); | 200 SmallStringKey(run.characters8(), length, run.direction()); |
198 else | 201 else |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 inline bool operator==(const ShapeCache::SmallStringKey& a, | 250 inline bool operator==(const ShapeCache::SmallStringKey& a, |
248 const ShapeCache::SmallStringKey& b) { | 251 const ShapeCache::SmallStringKey& b) { |
249 if (a.length() != b.length() || a.direction() != b.direction()) | 252 if (a.length() != b.length() || a.direction() != b.direction()) |
250 return false; | 253 return false; |
251 return WTF::equal(a.characters(), b.characters(), a.length()); | 254 return WTF::equal(a.characters(), b.characters(), a.length()); |
252 } | 255 } |
253 | 256 |
254 } // namespace blink | 257 } // namespace blink |
255 | 258 |
256 #endif // ShapeCache_h | 259 #endif // ShapeCache_h |
OLD | NEW |