Changeset 195392 in webkit
- Timestamp:
- Jan 20, 2016, 4:41:46 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
platform/graphics/cg/ColorCG.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r195386 r195392 1 2016-01-20 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 Use TinyLRUCache in caching the CGColorRef in WebCore::cachedCGColor() 4 https://bugs.webkit.org/show_bug.cgi?id=153279 5 6 Reviewed by Dean Jackson. 7 8 Reuse the new template TinyLRUCache in caching the CGColor instead of 9 having the same code repeated twice. 10 11 * platform/graphics/cg/ColorCG.cpp: 12 (WebCore::leakCGColor): 13 (WebCore::RetainPtr<CGColorRef>>::createValueForKey): 14 (WebCore::cachedCGColor): 15 1 16 2016-01-20 Timothy Hatcher <timothy@apple.com> 2 17 -
trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp
r192140 r195392 32 32 #include <wtf/Assertions.h> 33 33 #include <wtf/RetainPtr.h> 34 #include <wtf/TinyLRUCache.h> 34 35 #if !PLATFORM(IOS) 35 36 #include <ApplicationServices/ApplicationServices.h> … … 108 109 } 109 110 111 template<> 112 RetainPtr<CGColorRef> TinyLRUCachePolicy<Color, RetainPtr<CGColorRef>>::createValueForKey(const Color& color) 113 { 114 return adoptCF(leakCGColor(color)); 115 } 116 110 117 CGColorRef cachedCGColor(const Color& color) 111 118 { … … 127 134 ASSERT(color.rgb()); 128 135 129 const size_t cacheSize = 32; 130 static RGBA32 cachedRGBAValues[cacheSize]; 131 static RetainPtr<CGColorRef>* cachedCGColors = new RetainPtr<CGColorRef>[cacheSize]; 132 133 for (size_t i = 0; i < cacheSize; ++i) { 134 if (cachedRGBAValues[i] == color.rgb()) 135 return cachedCGColors[i].get(); 136 } 137 138 CGColorRef newCGColor = leakCGColor(color); 139 140 static size_t cursor; 141 cachedRGBAValues[cursor] = color.rgb(); 142 cachedCGColors[cursor] = adoptCF(newCGColor); 143 if (++cursor == cacheSize) 144 cursor = 0; 145 146 return newCGColor; 136 static NeverDestroyed<TinyLRUCache<Color, RetainPtr<CGColorRef>, 32>> cache; 137 return cache.get().get(color).get(); 147 138 } 148 139
Note:
See TracChangeset
for help on using the changeset viewer.