OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if ((m_singleCharMap.size() + m_map.size()) < s_maxSize) | 183 if ((m_singleCharMap.size() + m_map.size()) < s_maxSize) |
184 return value; | 184 return value; |
185 | 185 |
186 // No need to be fancy: we're just trying to avoid pathological growth. | 186 // No need to be fancy: we're just trying to avoid pathological growth. |
187 m_singleCharMap.clear(); | 187 m_singleCharMap.clear(); |
188 m_map.clear(); | 188 m_map.clear(); |
189 return 0; | 189 return 0; |
190 } | 190 } |
191 | 191 |
192 typedef HashMap<SmallStringKey, WidthCacheEntry, SmallStringKeyHash, SmallSt
ringKeyHashTraits> Map; | 192 typedef HashMap<SmallStringKey, WidthCacheEntry, SmallStringKeyHash, SmallSt
ringKeyHashTraits> Map; |
193 typedef HashMap<uint32_t, WidthCacheEntry, DefaultHash<uint32_t>::Hash, WTF:
:UnsignedWithZeroKeyHashTraits<uint32_t> > SingleCharMap; | 193 typedef HashMap<uint32_t, WidthCacheEntry, DefaultHash<uint32_t>::Hash, WTF:
:UnsignedWithZeroKeyHashTraits<uint32_t>> SingleCharMap; |
194 static const int s_minInterval = -3; // A cache hit pays for about 3 cache m
isses. | 194 static const int s_minInterval = -3; // A cache hit pays for about 3 cache m
isses. |
195 static const int s_maxInterval = 20; // Sampling at this interval has almost
no overhead. | 195 static const int s_maxInterval = 20; // Sampling at this interval has almost
no overhead. |
196 static const unsigned s_maxSize = 500000; // Just enough to guard against pa
thological growth. | 196 static const unsigned s_maxSize = 500000; // Just enough to guard against pa
thological growth. |
197 | 197 |
198 int m_interval; | 198 int m_interval; |
199 int m_countdown; | 199 int m_countdown; |
200 SingleCharMap m_singleCharMap; | 200 SingleCharMap m_singleCharMap; |
201 Map m_map; | 201 Map m_map; |
202 }; | 202 }; |
203 | 203 |
204 inline bool operator==(const WidthCache::SmallStringKey& a, const WidthCache::Sm
allStringKey& b) | 204 inline bool operator==(const WidthCache::SmallStringKey& a, const WidthCache::Sm
allStringKey& b) |
205 { | 205 { |
206 if (a.length() != b.length()) | 206 if (a.length() != b.length()) |
207 return false; | 207 return false; |
208 return WTF::equal(a.characters(), b.characters(), a.length()); | 208 return WTF::equal(a.characters(), b.characters(), a.length()); |
209 } | 209 } |
210 | 210 |
211 } // namespace blink | 211 } // namespace blink |
212 | 212 |
213 #endif // WidthCache_h | 213 #endif // WidthCache_h |
OLD | NEW |