@@ -111,7 +111,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
111111
112112 // Compute advances and store them
113113 mShaper ->computeValues (value.get (), paint,
114- reinterpret_cast <const UChar*>(text ), start, count,
114+ reinterpret_cast <const UChar*>(key. getText () ), start, count,
115115 size_t (contextCount), int (dirFlags));
116116
117117 if (mDebugEnabled ) {
@@ -139,15 +139,12 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
139139 // Update current cache size
140140 mSize += size;
141141
142- // Copy the text when we insert the new entry
143- key.internalTextCopy ();
144-
145142 bool putOne = mCache .put (key, value);
146143 LOG_ALWAYS_FATAL_IF (!putOne, " Failed to put an entry into the cache. "
147144 " This indicates that the cache already has an entry with the "
148145 " same key but it should not since we checked earlier!"
149146 " - start = %d, count = %d, contextCount = %d - Text = '%s'" ,
150- start, count, contextCount, String8 (text + start, count).string ());
147+ start, count, contextCount, String8 (key. getText () + start, count).string ());
151148
152149 if (mDebugEnabled ) {
153150 nsecs_t totalTime = systemTime (SYSTEM_TIME_MONOTONIC) - startTime;
@@ -158,7 +155,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
158155 value.get (), start, count, contextCount, size, mMaxSize - mSize ,
159156 value->getElapsedTime () * 0 .000001f ,
160157 (totalTime - value->getElapsedTime ()) * 0 .000001f ,
161- String8 (text + start, count).string ());
158+ String8 (key. getText () + start, count).string ());
162159 }
163160 } else {
164161 if (mDebugEnabled ) {
@@ -168,7 +165,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
168165 " - Compute time %0.6f ms - Text = '%s'" ,
169166 start, count, contextCount, size, mMaxSize - mSize ,
170167 value->getElapsedTime () * 0 .000001f ,
171- String8 (text + start, count).string ());
168+ String8 (key. getText () + start, count).string ());
172169 }
173170 }
174171 } else {
@@ -188,7 +185,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
188185 value->getElapsedTime () * 0 .000001f ,
189186 elapsedTimeThruCacheGet * 0 .000001f ,
190187 deltaPercent,
191- String8 (text + start, count).string ());
188+ String8 (key. getText () + start, count).string ());
192189 }
193190 if (mCacheHitCount % DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL == 0 ) {
194191 dumpCacheStats ();
@@ -225,15 +222,16 @@ void TextLayoutCache::dumpCacheStats() {
225222/* *
226223 * TextLayoutCacheKey
227224 */
228- TextLayoutCacheKey::TextLayoutCacheKey (): text( NULL ), start(0 ), count(0 ), contextCount(0 ),
225+ TextLayoutCacheKey::TextLayoutCacheKey (): start(0 ), count(0 ), contextCount(0 ),
229226 dirFlags (0 ), typeface(NULL ), textSize(0 ), textSkewX(0 ), textScaleX(0 ), flags(0 ),
230227 hinting(SkPaint::kNo_Hinting ), variant(SkPaint::kDefault_Variant ), language() {
231228}
232229
233230TextLayoutCacheKey::TextLayoutCacheKey (const SkPaint* paint, const UChar* text,
234231 size_t start, size_t count, size_t contextCount, int dirFlags) :
235- text(text), start(start), count(count), contextCount(contextCount),
232+ start(start), count(count), contextCount(contextCount),
236233 dirFlags(dirFlags) {
234+ textCopy.setTo (text, contextCount);
237235 typeface = paint->getTypeface ();
238236 textSize = paint->getTextSize ();
239237 textSkewX = paint->getTextSkewX ();
@@ -245,7 +243,6 @@ TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
245243}
246244
247245TextLayoutCacheKey::TextLayoutCacheKey (const TextLayoutCacheKey& other) :
248- text(NULL ),
249246 textCopy(other.textCopy),
250247 start(other.start),
251248 count(other.count),
@@ -259,9 +256,6 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
259256 hinting(other.hinting),
260257 variant(other.variant),
261258 language(other.language) {
262- if (other.text ) {
263- textCopy.setTo (other.text , other.contextCount );
264- }
265259}
266260
267261int TextLayoutCacheKey::compare (const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
@@ -304,11 +298,6 @@ int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutC
304298 return memcmp (lhs.getText (), rhs.getText (), lhs.contextCount * sizeof (UChar));
305299}
306300
307- void TextLayoutCacheKey::internalTextCopy () {
308- textCopy.setTo (text, contextCount);
309- text = NULL ;
310- }
311-
312301size_t TextLayoutCacheKey::getSize () const {
313302 return sizeof (TextLayoutCacheKey) + sizeof (UChar) * contextCount;
314303}
0 commit comments