[LFC][IFC] Use Optional for partialLeading/TrailingTextItem
https://bugs.webkit.org/show_bug.cgi?id=206423

Reviewed by Zalan Bujtas.

Remove the remaining InlineItem heap allocation.

* layout/inlineformatting/InlineItem.h:
* layout/inlineformatting/InlineTextItem.cpp:
(WebCore::Layout::InlineTextItem::left const): Deleted.
(WebCore::Layout::InlineTextItem::right const): Deleted.
* layout/inlineformatting/InlineTextItem.h:

Constructor can now be private.

(WebCore::Layout::InlineTextItem::left const):
(WebCore::Layout::InlineTextItem::right const):
* layout/inlineformatting/LineLayoutContext.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254754 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index e9f14b5..45fb9c6 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
+2020-01-17  Antti Koivisto  <antti@apple.com>
+
+        [LFC][IFC] Use Optional for partialLeading/TrailingTextItem
+        https://bugs.webkit.org/show_bug.cgi?id=206423
+
+        Reviewed by Zalan Bujtas.
+
+        Remove the remaining InlineItem heap allocation.
+
+        * layout/inlineformatting/InlineItem.h:
+        * layout/inlineformatting/InlineTextItem.cpp:
+        (WebCore::Layout::InlineTextItem::left const): Deleted.
+        (WebCore::Layout::InlineTextItem::right const): Deleted.
+        * layout/inlineformatting/InlineTextItem.h:
+
+        Constructor can now be private.
+
+        (WebCore::Layout::InlineTextItem::left const):
+        (WebCore::Layout::InlineTextItem::right const):
+        * layout/inlineformatting/LineLayoutContext.h:
+
 2020-01-17  Chris Dumez  <cdumez@apple.com>
 
         Drop dead code related to local storage prewarming
diff --git a/Source/WebCore/layout/inlineformatting/InlineItem.h b/Source/WebCore/layout/inlineformatting/InlineItem.h
index 26ddefc..420c7cb 100644
--- a/Source/WebCore/layout/inlineformatting/InlineItem.h
+++ b/Source/WebCore/layout/inlineformatting/InlineItem.h
@@ -33,7 +33,6 @@
 namespace Layout {
 
 class InlineItem {
-    WTF_MAKE_FAST_ALLOCATED;
 public:
     enum class Type : uint8_t { Text, HardLineBreak, SoftLineBreak, Box, Float, ContainerStart, ContainerEnd };
     InlineItem(const Box& layoutBox, Type);
diff --git a/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp b/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp
index 2f789a3..1cd33ba 100644
--- a/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp
+++ b/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp
@@ -127,22 +127,6 @@
     return !m_length || (m_length == 1 && layoutBox().textContext()->content[start()] == zeroWidthSpace); 
 }
 
-std::unique_ptr<InlineTextItem> InlineTextItem::left(unsigned length) const
-{
-    RELEASE_ASSERT(length <= this->length());
-    ASSERT(m_textItemType != TextItemType::Undefined);
-    ASSERT(length);
-    return makeUnique<InlineTextItem>(layoutBox(), start(), length, WTF::nullopt, m_textItemType);
-}
-
-std::unique_ptr<InlineTextItem> InlineTextItem::right(unsigned length) const
-{
-    RELEASE_ASSERT(length <= this->length());
-    ASSERT(m_textItemType != TextItemType::Undefined);
-    ASSERT(length);
-    return makeUnique<InlineTextItem>(layoutBox(), end() - length, length, WTF::nullopt, m_textItemType);
-}
-
 }
 }
 #endif
diff --git a/Source/WebCore/layout/inlineformatting/InlineTextItem.h b/Source/WebCore/layout/inlineformatting/InlineTextItem.h
index ec24114..2f17877 100644
--- a/Source/WebCore/layout/inlineformatting/InlineTextItem.h
+++ b/Source/WebCore/layout/inlineformatting/InlineTextItem.h
@@ -37,10 +37,6 @@
 public:
     static void createAndAppendTextItems(InlineItems&, const Box&);
 
-    static InlineTextItem createWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width);
-    static InlineTextItem createNonWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width);
-    static InlineTextItem createEmptyItem(const Box&);
-
     unsigned start() const { return m_startOrPosition; }
     unsigned end() const { return start() + length(); }
     unsigned length() const { return m_length; }
@@ -50,13 +46,18 @@
     Optional<InlineLayoutUnit> width() const { return m_hasWidth ? makeOptional(m_width) : Optional<InlineLayoutUnit> { }; }
     bool isEmptyContent() const;
 
-    std::unique_ptr<InlineTextItem> left(unsigned length) const;
-    std::unique_ptr<InlineTextItem> right(unsigned length) const;
+    InlineTextItem left(unsigned length) const;
+    InlineTextItem right(unsigned length) const;
 
+private:
     using InlineItem::TextItemType;
 
     InlineTextItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width, TextItemType);
     InlineTextItem(const Box&);
+
+    static InlineTextItem createWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width);
+    static InlineTextItem createNonWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width);
+    static InlineTextItem createEmptyItem(const Box&);
 };
 
 inline InlineTextItem InlineTextItem::createWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length, Optional<InlineLayoutUnit> width)
@@ -90,6 +91,22 @@
 {
 }
 
+inline InlineTextItem InlineTextItem::left(unsigned length) const
+{
+    RELEASE_ASSERT(length <= this->length());
+    ASSERT(m_textItemType != TextItemType::Undefined);
+    ASSERT(length);
+    return { layoutBox(), start(), length, WTF::nullopt, m_textItemType };
+}
+
+inline InlineTextItem InlineTextItem::right(unsigned length) const
+{
+    RELEASE_ASSERT(length <= this->length());
+    ASSERT(m_textItemType != TextItemType::Undefined);
+    ASSERT(length);
+    return { layoutBox(), end() - length, length, WTF::nullopt, m_textItemType };
+}
+
 }
 }
 
diff --git a/Source/WebCore/layout/inlineformatting/LineLayoutContext.h b/Source/WebCore/layout/inlineformatting/LineLayoutContext.h
index efd2614..538e993 100644
--- a/Source/WebCore/layout/inlineformatting/LineLayoutContext.h
+++ b/Source/WebCore/layout/inlineformatting/LineLayoutContext.h
@@ -75,8 +75,8 @@
     const Container& m_formattingContextRoot;
     const InlineItems& m_inlineItems;
     FloatList m_floats;
-    std::unique_ptr<InlineTextItem> m_partialLeadingTextItem;
-    std::unique_ptr<InlineTextItem> m_partialTrailingTextItem;
+    Optional<InlineTextItem> m_partialLeadingTextItem;
+    Optional<InlineTextItem> m_partialTrailingTextItem;
     unsigned m_successiveHyphenatedLineCount { 0 };
 };