@@ -77,15 +77,6 @@ bool operator == (decltype(nullptr), const SkStrikeCache::ExclusiveStrikePtr& rh
77
77
return nullptr == rhs.fStrike ;
78
78
}
79
79
80
- SkStrikeCache::~SkStrikeCache () {
81
- Strike* strike = fHead ;
82
- while (strike) {
83
- Strike* next = strike->fNext ;
84
- strike->unref ();
85
- strike = next;
86
- }
87
- }
88
-
89
80
SkExclusiveStrikePtr SkStrikeCache::findOrCreateStrikeExclusive (
90
81
const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface)
91
82
{
@@ -185,21 +176,24 @@ SkExclusiveStrikePtr SkStrikeCache::findStrikeExclusive(const SkDescriptor& desc
185
176
}
186
177
187
178
auto SkStrikeCache::internalFindStrikeOrNull (const SkDescriptor& desc) -> sk_sp<Strike> {
188
- Strike* strike = fStrikeLookup .findOrNull (desc);
189
- if (strike != nullptr && fHead != strike) {
179
+ sk_sp<Strike>* strikeHandle = fStrikeLookup .find (desc);
180
+ if (strikeHandle == nullptr ) { return nullptr ; }
181
+ Strike* strikePtr = strikeHandle->get ();
182
+ SkASSERT (strikePtr != nullptr );
183
+ if (fHead != strikePtr) {
190
184
// Make most recently used
191
- strike ->fPrev ->fNext = strike ->fNext ;
192
- if (strike ->fNext != nullptr ) {
193
- strike ->fNext ->fPrev = strike ->fPrev ;
185
+ strikePtr ->fPrev ->fNext = strikePtr ->fNext ;
186
+ if (strikePtr ->fNext != nullptr ) {
187
+ strikePtr ->fNext ->fPrev = strikePtr ->fPrev ;
194
188
} else {
195
- fTail = strike ->fPrev ;
189
+ fTail = strikePtr ->fPrev ;
196
190
}
197
- fHead ->fPrev = strike ;
198
- strike ->fNext = fHead ;
199
- strike ->fPrev = nullptr ;
200
- fHead = strike ;
191
+ fHead ->fPrev = strikePtr ;
192
+ strikePtr ->fNext = fHead ;
193
+ strikePtr ->fPrev = nullptr ;
194
+ fHead = strikePtr ;
201
195
}
202
- return sk_ref_sp (strike );
196
+ return sk_ref_sp (strikePtr );
203
197
}
204
198
205
199
SkExclusiveStrikePtr SkStrikeCache::createStrikeExclusive (
@@ -359,23 +353,24 @@ size_t SkStrikeCache::internalPurge(size_t minBytesNeeded) {
359
353
}
360
354
361
355
void SkStrikeCache::internalAttachToHead (sk_sp<Strike> strike) {
362
- SkASSERT (nullptr == strike->fPrev && nullptr == strike->fNext );
356
+ SkASSERT (fStrikeLookup .find (strike->getDescriptor ()) == nullptr );
357
+ Strike* strikePtr = strike.get ();
358
+ fStrikeLookup .set (std::move (strike));
359
+ SkASSERT (nullptr == strikePtr->fPrev && nullptr == strikePtr->fNext );
363
360
364
361
fCacheCount += 1 ;
365
- fTotalMemoryUsed += strike ->fMemoryUsed ;
362
+ fTotalMemoryUsed += strikePtr ->fMemoryUsed ;
366
363
367
- if (fHead ) {
368
- fHead ->fPrev = strike. get () ;
369
- strike ->fNext = fHead ;
364
+ if (fHead != nullptr ) {
365
+ fHead ->fPrev = strikePtr ;
366
+ strikePtr ->fNext = fHead ;
370
367
}
371
368
372
369
if (fTail == nullptr ) {
373
- fTail = strike. get () ;
370
+ fTail = strikePtr ;
374
371
}
375
372
376
- fStrikeLookup .set (strike.get ());
377
-
378
- fHead = strike.release (); // Transfer ownership of strike to the cache list.
373
+ fHead = strikePtr; // Transfer ownership of strike to the cache list.
379
374
}
380
375
381
376
void SkStrikeCache::internalRemoveStrike (Strike* strike) {
@@ -394,10 +389,9 @@ void SkStrikeCache::internalRemoveStrike(Strike* strike) {
394
389
fTail = strike->fPrev ;
395
390
}
396
391
397
- fStrikeLookup .remove (strike->getDescriptor ());
398
392
strike->fPrev = strike->fNext = nullptr ;
399
393
strike->fRemoved = true ;
400
- strike->unref ( );
394
+ fStrikeLookup . remove ( strike->getDescriptor () );
401
395
}
402
396
403
397
void SkStrikeCache::validate () const {
@@ -413,7 +407,6 @@ void SkStrikeCache::validate() const {
413
407
strike = strike->fNext ;
414
408
}
415
409
416
- // Can't use SkASSERTF because it looses thread annotations.
417
410
if (fCacheCount != computedCount) {
418
411
SkDebugf (" fCacheCount: %d, computedCount: %d" , fCacheCount , computedCount);
419
412
SK_ABORT (" fCacheCount != computedCount" );
0 commit comments