Bug 87824 - Factor DeferrableOneShotTimer out of GraphicsContextCG/GeneratorGeneratedImage
Summary: Factor DeferrableOneShotTimer out of GraphicsContextCG/GeneratorGeneratedImage
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Horton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-29 22:54 PDT by Tim Horton
Modified: 2012-06-04 10:05 PDT (History)
2 users (show)

See Also:


Attachments
patch (8.03 KB, patch)
2012-05-29 23:31 PDT, Tim Horton
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2012-05-29 22:54:34 PDT
I copied and pasted some code from GraphicsContextCG into GeneratorGeneratedImage, and I shouldn't have. We should move this code to somewhere more generic so that it can be reused, especially as it's particularly useful for clearing caches!

DeferrableOneShotTimer is a timer which takes a class+method to call (as Timer does), and a delay. It exposes restart(), stop(), and isActive(), and none of the rest of the TimerBase interface. On restart(), the timer is started with the given delay, unless it's already running, in which case a flag is set to automatically restart the timer when it fires instead of calling the given method. This provides a low-overhead way to implement a deferrable timer.

This will be used to clear GraphicsContextCG's subimage cache and GeneratorGeneratedImage's generated image cache.

I have a patch. I'm also open to better names and/or moving it into its own header if needed.
Comment 1 Tim Horton 2012-05-29 23:31:55 PDT
Created attachment 144724 [details]
patch
Comment 2 Simon Fraser (smfr) 2012-05-30 09:02:33 PDT
Comment on attachment 144724 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=144724&action=review

Nice.

> Source/WebCore/platform/Timer.h:127
> +        // again, which might result in rescheduling the system timer and that

s/and that/which

> Source/WebCore/platform/Timer.h:155
> +    bool m_shouldRestartWhenTimerFires;
> +    double m_delay;

Putting the bool last might get you better packing and a smaller object.
Comment 3 Tim Horton 2012-05-30 11:28:53 PDT
http://trac.webkit.org/changeset/118942
Comment 4 Darin Adler 2012-05-30 12:48:46 PDT
Comment on attachment 144724 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=144724&action=review

>> Source/WebCore/platform/Timer.h:127
>> +        // again, which might result in rescheduling the system timer and that
> 
> s/and that/which

I don’t agree. That goes against my elementary school training about the use of which vs. that.