Title: [231940] trunk/Source/WebCore
Revision
231940
Author
ddkil...@apple.com
Date
2018-05-17 20:29:19 -0700 (Thu, 17 May 2018)

Log Message

Lazily create WebCore::Timer for WebCore::Image
<https://webkit.org/b/185752>

Reviewed by Simon Fraser.

Not every image is an animated image, so lazily creating
m_animationStartTimer saves 64 bytes per instance of
WebCore::Image.

* platform/graphics/Image.cpp:
(WebCore::Image::Image): Remove default initializer for
m_animationStartTimer.
(WebCore::Image::startAnimationAsynchronously): Initialize
m_animationStartTimer if it's not already created.
* platform/graphics/Image.h:
(WebCore::Image::animationPending const): Update to check if
m_animationStartTimer has been set before dereferencing it.
(WebCore::Image::m_animationStartTimer): Change type to
std::unique_ptr<Timer>.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231939 => 231940)


--- trunk/Source/WebCore/ChangeLog	2018-05-18 02:59:31 UTC (rev 231939)
+++ trunk/Source/WebCore/ChangeLog	2018-05-18 03:29:19 UTC (rev 231940)
@@ -1,3 +1,25 @@
+2018-05-17  David Kilzer  <ddkil...@apple.com>
+
+        Lazily create WebCore::Timer for WebCore::Image
+        <https://webkit.org/b/185752>
+
+        Reviewed by Simon Fraser.
+
+        Not every image is an animated image, so lazily creating
+        m_animationStartTimer saves 64 bytes per instance of
+        WebCore::Image.
+
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::Image): Remove default initializer for
+        m_animationStartTimer.
+        (WebCore::Image::startAnimationAsynchronously): Initialize
+        m_animationStartTimer if it's not already created.
+        * platform/graphics/Image.h:
+        (WebCore::Image::animationPending const): Update to check if
+        m_animationStartTimer has been set before dereferencing it.
+        (WebCore::Image::m_animationStartTimer): Change type to
+        std::unique_ptr<Timer>.
+
 2018-05-17  Nan Wang  <n_w...@apple.com>
 
         AX: [macOS] Expose the primary screen height through AX API

Modified: trunk/Source/WebCore/platform/graphics/Image.cpp (231939 => 231940)


--- trunk/Source/WebCore/platform/graphics/Image.cpp	2018-05-18 02:59:31 UTC (rev 231939)
+++ trunk/Source/WebCore/platform/graphics/Image.cpp	2018-05-18 03:29:19 UTC (rev 231940)
@@ -50,7 +50,6 @@
 
 Image::Image(ImageObserver* observer)
     : m_imageObserver(observer)
-    , m_animationStartTimer(*this, &Image::startAnimation)
 {
 }
 
@@ -349,9 +348,11 @@
 
 void Image::startAnimationAsynchronously()
 {
-    if (m_animationStartTimer.isActive())
+    if (!m_animationStartTimer)
+        m_animationStartTimer = std::make_unique<Timer>(*this, &Image::startAnimation);
+    if (m_animationStartTimer->isActive())
         return;
-    m_animationStartTimer.startOneShot(0_s);
+    m_animationStartTimer->startOneShot(0_s);
 }
 
 void Image::dump(TextStream& ts) const

Modified: trunk/Source/WebCore/platform/graphics/Image.h (231939 => 231940)


--- trunk/Source/WebCore/platform/graphics/Image.h	2018-05-18 02:59:31 UTC (rev 231939)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2018-05-18 03:29:19 UTC (rev 231940)
@@ -138,7 +138,7 @@
     virtual void stopAnimation() {}
     virtual void resetAnimation() {}
     virtual bool isAnimating() const { return false; }
-    bool animationPending() const { return m_animationStartTimer.isActive(); }
+    bool animationPending() const { return m_animationStartTimer && m_animationStartTimer->isActive(); }
 
     // Typically the CachedImage that owns us.
     ImageObserver* imageObserver() const { return m_imageObserver; }
@@ -200,7 +200,7 @@
 private:
     RefPtr<SharedBuffer> m_encodedImageData;
     ImageObserver* m_imageObserver;
-    Timer m_animationStartTimer;
+    std::unique_ptr<Timer> m_animationStartTimer;
 };
 
 WTF::TextStream& operator<<(WTF::TextStream&, const Image&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to