Title: [294010] trunk/Source/WebCore
Revision
294010
Author
[email protected]
Date
2022-05-10 10:28:37 -0700 (Tue, 10 May 2022)

Log Message

Optimize Replayer::applyItem() slightly
https://bugs.webkit.org/show_bug.cgi?id=240258

Reviewed by Wenson Hsieh.

Convert a series of `if` statements into a switch.

De-templatize applyFontItem<> since DrawGlyphs is the only instantiation, and the
name was confusing.

* platform/graphics/displaylists/DisplayListReplayer.cpp:
(WebCore::DisplayList::applyDrawGlyphs):
(WebCore::DisplayList::Replayer::applyItem):
(WebCore::DisplayList::applyFontItem): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (294009 => 294010)


--- trunk/Source/WebCore/ChangeLog	2022-05-10 17:00:47 UTC (rev 294009)
+++ trunk/Source/WebCore/ChangeLog	2022-05-10 17:28:37 UTC (rev 294010)
@@ -1,3 +1,20 @@
+2022-05-10  Simon Fraser  <[email protected]>
+
+        Optimize Replayer::applyItem() slightly
+        https://bugs.webkit.org/show_bug.cgi?id=240258
+
+        Reviewed by Wenson Hsieh.
+
+        Convert a series of `if` statements into a switch.
+
+        De-templatize applyFontItem<> since DrawGlyphs is the only instantiation, and the
+        name was confusing.
+
+        * platform/graphics/displaylists/DisplayListReplayer.cpp:
+        (WebCore::DisplayList::applyDrawGlyphs):
+        (WebCore::DisplayList::Replayer::applyItem):
+        (WebCore::DisplayList::applyFontItem): Deleted.
+
 2022-05-10  Brent Fulgham  <[email protected]>
 
         Remove abandoned CSSDeferredParser implementation and feature flag

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp (294009 => 294010)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp	2022-05-10 17:00:47 UTC (rev 294009)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp	2022-05-10 17:28:37 UTC (rev 294010)
@@ -107,13 +107,11 @@
     return std::nullopt;
 }
 
-template<class T>
-inline static std::optional<RenderingResourceIdentifier> applyFontItem(GraphicsContext& context, const ResourceHeap& resourceHeap, ItemHandle item)
+inline static std::optional<RenderingResourceIdentifier> applyDrawGlyphs(GraphicsContext& context, const ResourceHeap& resourceHeap, DrawGlyphs& drawGlyphsItem)
 {
-    auto& fontItem = item.get<T>();
-    auto resourceIdentifier = fontItem.fontIdentifier();
+    auto resourceIdentifier = drawGlyphsItem.fontIdentifier();
     if (auto* font = resourceHeap.getFont(resourceIdentifier)) {
-        fontItem.apply(context, *font);
+        drawGlyphsItem.apply(context, *font);
         return std::nullopt;
     }
     return resourceIdentifier;
@@ -121,43 +119,42 @@
 
 std::pair<std::optional<StopReplayReason>, std::optional<RenderingResourceIdentifier>> Replayer::applyItem(ItemHandle item)
 {
-    if (item.is<DrawImageBuffer>()) {
-        if (auto missingCachedResourceIdentifier = applyImageBufferItem<DrawImageBuffer>(m_context, m_resourceHeap, item))
+    switch (item.type()) {
+    case ItemType::ClipToImageBuffer:
+        if (auto missingCachedResourceIdentifier = applyImageBufferItem<ClipToImageBuffer>(m_context, m_resourceHeap, item))
             return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };
         return { std::nullopt, std::nullopt };
-    }
 
-    if (item.is<ClipToImageBuffer>()) {
-        if (auto missingCachedResourceIdentifier = applyImageBufferItem<ClipToImageBuffer>(m_context, m_resourceHeap, item))
+    case ItemType::DrawGlyphs:
+        if (auto missingCachedResourceIdentifier = applyDrawGlyphs(m_context, m_resourceHeap, item.get<DrawGlyphs>()))
             return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };
         return { std::nullopt, std::nullopt };
-    }
 
-    if (item.is<DrawNativeImage>()) {
-        if (auto missingCachedResourceIdentifier = applyNativeImageItem<DrawNativeImage>(m_context, m_resourceHeap, item))
+    case ItemType::DrawImageBuffer:
+        if (auto missingCachedResourceIdentifier = applyImageBufferItem<DrawImageBuffer>(m_context, m_resourceHeap, item))
             return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };
         return { std::nullopt, std::nullopt };
-    }
 
-    if (item.is<DrawGlyphs>()) {
-        if (auto missingCachedResourceIdentifier = applyFontItem<DrawGlyphs>(m_context, m_resourceHeap, item))
+    case ItemType::DrawNativeImage:
+        if (auto missingCachedResourceIdentifier = applyNativeImageItem<DrawNativeImage>(m_context, m_resourceHeap, item))
             return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };
         return { std::nullopt, std::nullopt };
-    }
 
-    if (item.is<DrawPattern>()) {
+    case ItemType::DrawPattern:
         if (auto missingCachedResourceIdentifier = applySourceImageItem<DrawPattern>(m_context, m_resourceHeap, item))
             return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };
         return { std::nullopt, std::nullopt };
-    }
 
-    if (item.is<SetState>()) {
+    case ItemType::SetState:
         if (auto missingCachedResourceIdentifier = applySetStateItem(m_context, m_resourceHeap, item))
             return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };
         return { std::nullopt, std::nullopt };
+
+    default:
+        item.apply(m_context);
+        return { std::nullopt, std::nullopt };
     }
 
-    item.apply(m_context);
     return { std::nullopt, std::nullopt };
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to