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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 public: | 124 public: |
125 WidthCache() | 125 WidthCache() |
126 : m_interval(s_maxInterval) | 126 : m_interval(s_maxInterval) |
127 , m_countdown(m_interval) | 127 , m_countdown(m_interval) |
128 { | 128 { |
129 } | 129 } |
130 | 130 |
131 WidthCacheEntry* add(const TextRun& run, WidthCacheEntry entry) | 131 WidthCacheEntry* add(const TextRun& run, WidthCacheEntry entry) |
132 { | 132 { |
133 if (run.length() > SmallStringKey::capacity()) | 133 if (static_cast<unsigned>(run.length()) > SmallStringKey::capacity()) |
134 return 0; | 134 return 0; |
135 | 135 |
136 if (m_countdown > 0) { | 136 if (m_countdown > 0) { |
137 --m_countdown; | 137 --m_countdown; |
138 return 0; | 138 return 0; |
139 } | 139 } |
140 | 140 |
141 return addSlowCase(run, entry); | 141 return addSlowCase(run, entry); |
142 } | 142 } |
143 | 143 |
144 void clear() | 144 void clear() |
145 { | 145 { |
146 m_singleCharMap.clear(); | 146 m_singleCharMap.clear(); |
147 m_map.clear(); | 147 m_map.clear(); |
148 } | 148 } |
149 | 149 |
150 private: | 150 private: |
151 WidthCacheEntry* addSlowCase(const TextRun& run, WidthCacheEntry entry) | 151 WidthCacheEntry* addSlowCase(const TextRun& run, WidthCacheEntry entry) |
152 { | 152 { |
153 unsigned length = run.length(); | 153 int length = run.length(); |
154 bool isNewEntry; | 154 bool isNewEntry; |
155 WidthCacheEntry *value; | 155 WidthCacheEntry *value; |
156 if (length == 1) { | 156 if (length == 1) { |
157 SingleCharMap::AddResult addResult = m_singleCharMap.add(run[0], ent
ry); | 157 SingleCharMap::AddResult addResult = m_singleCharMap.add(run[0], ent
ry); |
158 isNewEntry = addResult.isNewEntry; | 158 isNewEntry = addResult.isNewEntry; |
159 value = &addResult.storedValue->value; | 159 value = &addResult.storedValue->value; |
160 } else { | 160 } else { |
161 SmallStringKey smallStringKey; | 161 SmallStringKey smallStringKey; |
162 if (run.is8Bit()) | 162 if (run.is8Bit()) |
163 smallStringKey = SmallStringKey(run.characters8(), length); | 163 smallStringKey = SmallStringKey(run.characters8(), length); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |