⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 195392 in webkit


Ignore:
Timestamp:
Jan 20, 2016, 4:41:46 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Use TinyLRUCache in caching the CGColorRef in WebCore::cachedCGColor()
https://bugs.webkit.org/show_bug.cgi?id=153279

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2016-01-20
Reviewed by Dean Jackson.

Reuse the new template TinyLRUCache in caching the CGColor instead of
having the same code repeated twice.

  • platform/graphics/cg/ColorCG.cpp:

(WebCore::leakCGColor):
(WebCore::RetainPtr<CGColorRef>>::createValueForKey):
(WebCore::cachedCGColor):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r195386 r195392  
     12016-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
    1162016-01-20  Timothy Hatcher  <timothy@apple.com>
    217
  • trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp

    r192140 r195392  
    3232#include <wtf/Assertions.h>
    3333#include <wtf/RetainPtr.h>
     34#include <wtf/TinyLRUCache.h>
    3435#if !PLATFORM(IOS)
    3536#include <ApplicationServices/ApplicationServices.h>
     
    108109}
    109110
     111template<>
     112RetainPtr<CGColorRef> TinyLRUCachePolicy<Color, RetainPtr<CGColorRef>>::createValueForKey(const Color& color)
     113{
     114    return adoptCF(leakCGColor(color));
     115}
     116
    110117CGColorRef cachedCGColor(const Color& color)
    111118{
     
    127134    ASSERT(color.rgb());
    128135
    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();
    147138}
    148139
Note: See TracChangeset for help on using the changeset viewer.