WebKit Bugzilla
Attachment 345850 Details for
Bug 188062
: Reduce unnecessary copying of EditingStyles on ApplyStyleCommand construction
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188062-20180726102017.patch (text/plain), 21.76 KB, created by
Sam Weinig
on 2018-07-26 10:20:18 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Sam Weinig
Created:
2018-07-26 10:20:18 PDT
Size:
21.76 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 234266) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,42 @@ >+2018-07-26 Sam Weinig <sam@webkit.org> >+ >+ Reduce unnecessary copying of EditingStyles on ApplyStyleCommand construction >+ https://bugs.webkit.org/show_bug.cgi?id=188062 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Instead of always copying the EditingStyle passed to the ApplyStyleCommand >+ constructor, move a Ref<EditingStyle> in instead, making the few callers >+ who really do want to make a copy, to make a copy themselves. >+ >+ * editing/ApplyStyleCommand.cpp: >+ (WebCore::ApplyStyleCommand::ApplyStyleCommand): >+ * editing/ApplyStyleCommand.h: >+ (WebCore::ApplyStyleCommand::create): >+ * editing/CompositeEditCommand.cpp: >+ (WebCore::CompositeEditCommand::applyStyle): >+ (WebCore::CompositeEditCommand::moveParagraphs): >+ * editing/CompositeEditCommand.h: >+ * editing/Editor.cpp: >+ (WebCore::Editor::applyStyle): >+ (WebCore::Editor::applyParagraphStyle): >+ (WebCore::Editor::computeAndSetTypingStyle): >+ * editing/Editor.h: >+ * editing/EditorCommand.cpp: >+ (WebCore::executeMakeTextWritingDirectionLeftToRight): >+ (WebCore::executeMakeTextWritingDirectionNatural): >+ (WebCore::executeMakeTextWritingDirectionRightToLeft): >+ * editing/InsertLineBreakCommand.cpp: >+ (WebCore::InsertLineBreakCommand::doApply): >+ * editing/InsertParagraphSeparatorCommand.cpp: >+ (WebCore::InsertParagraphSeparatorCommand::applyStyleAfterInsertion): >+ * editing/InsertTextCommand.cpp: >+ (WebCore::InsertTextCommand::doApply): >+ * editing/RemoveFormatCommand.cpp: >+ (WebCore::RemoveFormatCommand::doApply): >+ * editing/ReplaceSelectionCommand.cpp: >+ (WebCore::ReplaceSelectionCommand::completeHTMLReplacement): >+ > 2018-07-26 Eric Carlson <eric.carlson@apple.com> > > Switching tabs should not close PiP window >Index: Source/WebCore/editing/ApplyStyleCommand.cpp >=================================================================== >--- Source/WebCore/editing/ApplyStyleCommand.cpp (revision 234266) >+++ Source/WebCore/editing/ApplyStyleCommand.cpp (working copy) >@@ -124,9 +124,9 @@ Ref<HTMLElement> createStyleSpanElement( > return createHTMLElement(document, spanTag); > } > >-ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* style, EditAction editingAction, EPropertyLevel propertyLevel) >+ApplyStyleCommand::ApplyStyleCommand(Document& document, Ref<EditingStyle>&& style, EditAction editingAction, EPropertyLevel propertyLevel) > : CompositeEditCommand(document, editingAction) >- , m_style(style->copy()) >+ , m_style(WTFMove(style)) > , m_propertyLevel(propertyLevel) > , m_start(endingSelection().start().downstream()) > , m_end(endingSelection().end().upstream()) >@@ -135,9 +135,9 @@ ApplyStyleCommand::ApplyStyleCommand(Doc > { > } > >-ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* style, const Position& start, const Position& end, EditAction editingAction, EPropertyLevel propertyLevel) >+ApplyStyleCommand::ApplyStyleCommand(Document& document, Ref<EditingStyle>&& style, const Position& start, const Position& end, EditAction editingAction, EPropertyLevel propertyLevel) > : CompositeEditCommand(document, editingAction) >- , m_style(style->copy()) >+ , m_style(WTFMove(style)) > , m_propertyLevel(propertyLevel) > , m_start(start) > , m_end(end) >@@ -158,9 +158,9 @@ ApplyStyleCommand::ApplyStyleCommand(Ref > { > } > >-ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction editingAction) >+ApplyStyleCommand::ApplyStyleCommand(Document& document, Ref<EditingStyle>&& style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction editingAction) > : CompositeEditCommand(document, editingAction) >- , m_style(style->copy()) >+ , m_style(WTFMove(style)) > , m_propertyLevel(PropertyDefault) > , m_start(endingSelection().start().downstream()) > , m_end(endingSelection().end().upstream()) >Index: Source/WebCore/editing/ApplyStyleCommand.h >=================================================================== >--- Source/WebCore/editing/ApplyStyleCommand.h (revision 234266) >+++ Source/WebCore/editing/ApplyStyleCommand.h (working copy) >@@ -47,28 +47,28 @@ public: > enum EAddStyledElement { AddStyledElement, DoNotAddStyledElement }; > typedef bool (*IsInlineElementToRemoveFunction)(const Element*); > >- static Ref<ApplyStyleCommand> create(Document& document, const EditingStyle* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault) >+ static Ref<ApplyStyleCommand> create(Document& document, Ref<EditingStyle>&& style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault) > { >- return adoptRef(*new ApplyStyleCommand(document, style, action, level)); >+ return adoptRef(*new ApplyStyleCommand(document, WTFMove(style), action, level)); > } >- static Ref<ApplyStyleCommand> create(Document& document, const EditingStyle* style, const Position& start, const Position& end, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault) >+ static Ref<ApplyStyleCommand> create(Document& document, Ref<EditingStyle>&& style, const Position& start, const Position& end, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault) > { >- return adoptRef(*new ApplyStyleCommand(document, style, start, end, action, level)); >+ return adoptRef(*new ApplyStyleCommand(document, WTFMove(style), start, end, action, level)); > } > static Ref<ApplyStyleCommand> create(Ref<Element>&& element, bool removeOnly = false, EditAction action = EditActionChangeAttributes) > { > return adoptRef(*new ApplyStyleCommand(WTFMove(element), removeOnly, action)); > } >- static Ref<ApplyStyleCommand> create(Document& document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction action = EditActionChangeAttributes) >+ static Ref<ApplyStyleCommand> create(Document& document, Ref<EditingStyle>&& style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction action = EditActionChangeAttributes) > { >- return adoptRef(*new ApplyStyleCommand(document, style, isInlineElementToRemoveFunction, action)); >+ return adoptRef(*new ApplyStyleCommand(document, WTFMove(style), isInlineElementToRemoveFunction, action)); > } > > private: >- ApplyStyleCommand(Document&, const EditingStyle*, EditAction, EPropertyLevel); >- ApplyStyleCommand(Document&, const EditingStyle*, const Position& start, const Position& end, EditAction, EPropertyLevel); >+ ApplyStyleCommand(Document&, Ref<EditingStyle>&&, EditAction, EPropertyLevel); >+ ApplyStyleCommand(Document&, Ref<EditingStyle>&&, const Position& start, const Position& end, EditAction, EPropertyLevel); > ApplyStyleCommand(Ref<Element>&&, bool removeOnly, EditAction); >- ApplyStyleCommand(Document&, const EditingStyle*, bool (*isInlineElementToRemove)(const Element*), EditAction); >+ ApplyStyleCommand(Document&, Ref<EditingStyle>&&, bool (*isInlineElementToRemove)(const Element*), EditAction); > > void doApply() override; > bool shouldDispatchInputEvents() const final { return false; } >Index: Source/WebCore/editing/CompositeEditCommand.cpp >=================================================================== >--- Source/WebCore/editing/CompositeEditCommand.cpp (revision 234266) >+++ Source/WebCore/editing/CompositeEditCommand.cpp (working copy) >@@ -474,14 +474,14 @@ void CompositeEditCommand::applyCommandT > m_commands.append(WTFMove(command)); > } > >-void CompositeEditCommand::applyStyle(const EditingStyle* style, EditAction editingAction) >+void CompositeEditCommand::applyStyle(Ref<EditingStyle>&& style, EditAction editingAction) > { >- applyCommandToComposite(ApplyStyleCommand::create(document(), style, editingAction)); >+ applyCommandToComposite(ApplyStyleCommand::create(document(), WTFMove(style), editingAction)); > } > >-void CompositeEditCommand::applyStyle(const EditingStyle* style, const Position& start, const Position& end, EditAction editingAction) >+void CompositeEditCommand::applyStyle(Ref<EditingStyle>&& style, const Position& start, const Position& end, EditAction editingAction) > { >- applyCommandToComposite(ApplyStyleCommand::create(document(), style, start, end, editingAction)); >+ applyCommandToComposite(ApplyStyleCommand::create(document(), WTFMove(style), start, end, editingAction)); > } > > void CompositeEditCommand::applyStyledElement(Ref<Element>&& element) >@@ -1499,7 +1499,7 @@ void CompositeEditCommand::moveParagraph > // If the selection is in an empty paragraph, restore styles from the old empty paragraph to the new empty paragraph. > bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfParagraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().visibleStart()); > if (styleInEmptyParagraph && selectionIsEmptyParagraph) >- applyStyle(styleInEmptyParagraph.get()); >+ applyStyle(styleInEmptyParagraph.releaseNonNull()); > > if (preserveSelection && startIndex != -1) { > // Fragment creation (using createMarkup) incorrectly uses regular >@@ -1585,7 +1585,7 @@ bool CompositeEditCommand::breakOutOfEmp > > style->prepareToApplyAt(endingSelection().start()); > if (!style->isEmpty()) >- applyStyle(style.ptr()); >+ applyStyle(WTFMove(style)); > > return true; > } >Index: Source/WebCore/editing/CompositeEditCommand.h >=================================================================== >--- Source/WebCore/editing/CompositeEditCommand.h (revision 234266) >+++ Source/WebCore/editing/CompositeEditCommand.h (working copy) >@@ -136,8 +136,8 @@ protected: > void appendNode(Ref<Node>&&, Ref<ContainerNode>&& parent); > void applyCommandToComposite(Ref<EditCommand>&&); > void applyCommandToComposite(Ref<CompositeEditCommand>&&, const VisibleSelection&); >- void applyStyle(const EditingStyle*, EditAction = EditActionChangeAttributes); >- void applyStyle(const EditingStyle*, const Position& start, const Position& end, EditAction = EditActionChangeAttributes); >+ void applyStyle(Ref<EditingStyle>&&, EditAction = EditActionChangeAttributes); >+ void applyStyle(Ref<EditingStyle>&&, const Position& start, const Position& end, EditAction = EditActionChangeAttributes); > void applyStyledElement(Ref<Element>&&); > void removeStyledElement(Ref<Element>&&); > void deleteSelection(bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = true, bool sanitizeMarkup = true); >Index: Source/WebCore/editing/Editor.cpp >=================================================================== >--- Source/WebCore/editing/Editor.cpp (revision 234266) >+++ Source/WebCore/editing/Editor.cpp (working copy) >@@ -895,29 +895,26 @@ void Editor::applyStyle(StyleProperties* > applyStyle(EditingStyle::create(style), editingAction, ColorFilterMode::UseOriginalColor); > } > >-void Editor::applyStyle(RefPtr<EditingStyle>&& style, EditAction editingAction, ColorFilterMode colorFilterMode) >+void Editor::applyStyle(Ref<EditingStyle>&& style, EditAction editingAction, ColorFilterMode colorFilterMode) > { >- if (!style) >- return; >- > auto selectionType = m_frame.selection().selection().selectionType(); > if (selectionType == VisibleSelection::NoSelection) > return; > > String inputTypeName = inputTypeNameForEditingAction(editingAction); >- String inputEventData = inputEventDataForEditingStyleAndAction(*style, editingAction); >+ String inputEventData = inputEventDataForEditingStyleAndAction(style.get(), editingAction); > RefPtr<Element> element = m_frame.selection().selection().rootEditableElement(); > if (element && !dispatchBeforeInputEvent(*element, inputTypeName, inputEventData)) > return; > >- Ref<EditingStyle> styleToApply = colorFilterMode == ColorFilterMode::InvertColor ? style->inverseTransformColorIfNeeded(*element) : style.releaseNonNull(); >+ Ref<EditingStyle> styleToApply = colorFilterMode == ColorFilterMode::InvertColor ? style->inverseTransformColorIfNeeded(*element) : WTFMove(style); > > switch (selectionType) { > case VisibleSelection::CaretSelection: > computeAndSetTypingStyle(styleToApply.get(), editingAction); > break; > case VisibleSelection::RangeSelection: >- ApplyStyleCommand::create(document(), styleToApply.ptr(), editingAction)->apply(); >+ ApplyStyleCommand::create(document(), WTFMove(styleToApply), editingAction)->apply(); > break; > default: > break; >@@ -948,7 +945,7 @@ void Editor::applyParagraphStyle(StylePr > if (element && !dispatchBeforeInputEvent(*element, inputTypeName, inputEventData)) > return; > >- ApplyStyleCommand::create(document(), EditingStyle::create(style).ptr(), editingAction, ApplyStyleCommand::ForceBlockProperties)->apply(); >+ ApplyStyleCommand::create(document(), EditingStyle::create(style), editingAction, ApplyStyleCommand::ForceBlockProperties)->apply(); > client()->didApplyStyle(); > if (element) > dispatchInputEvent(*element, inputTypeName, inputEventData); >@@ -3224,9 +3221,9 @@ void Editor::computeAndSetTypingStyle(Ed > typingStyle->overrideTypingStyleAt(style, m_frame.selection().selection().visibleStart().deepEquivalent()); > > // Handle block styles, substracting these from the typing style. >- RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperties(); >+ auto blockStyle = typingStyle->extractAndRemoveBlockProperties(); > if (!blockStyle->isEmpty()) >- ApplyStyleCommand::create(document(), blockStyle.get(), editingAction)->apply(); >+ ApplyStyleCommand::create(document(), WTFMove(blockStyle), editingAction)->apply(); > > // Set the remaining style as the typing style. > m_frame.selection().setTypingStyle(WTFMove(typingStyle)); >Index: Source/WebCore/editing/Editor.h >=================================================================== >--- Source/WebCore/editing/Editor.h (revision 234266) >+++ Source/WebCore/editing/Editor.h (working copy) >@@ -217,7 +217,7 @@ public: > > WEBCORE_EXPORT void applyStyle(StyleProperties*, EditAction = EditActionUnspecified); > enum class ColorFilterMode { InvertColor, UseOriginalColor }; >- void applyStyle(RefPtr<EditingStyle>&&, EditAction, ColorFilterMode); >+ void applyStyle(Ref<EditingStyle>&&, EditAction, ColorFilterMode); > void applyParagraphStyle(StyleProperties*, EditAction = EditActionUnspecified); > WEBCORE_EXPORT void applyStyleToSelection(StyleProperties*, EditAction); > WEBCORE_EXPORT void applyStyleToSelection(Ref<EditingStyle>&&, EditAction, ColorFilterMode); >@@ -406,8 +406,8 @@ public: > const VisibleSelection& mark() const; // Mark, to be used as emacs uses it. > void setMark(const VisibleSelection&); > >- void computeAndSetTypingStyle(EditingStyle& , EditAction = EditActionUnspecified); >- WEBCORE_EXPORT void computeAndSetTypingStyle(StyleProperties& , EditAction = EditActionUnspecified); >+ void computeAndSetTypingStyle(EditingStyle&, EditAction = EditActionUnspecified); >+ WEBCORE_EXPORT void computeAndSetTypingStyle(StyleProperties&, EditAction = EditActionUnspecified); > WEBCORE_EXPORT void applyEditingStyleToBodyElement() const; > void applyEditingStyleToElement(Element*) const; > >Index: Source/WebCore/editing/EditorCommand.cpp >=================================================================== >--- Source/WebCore/editing/EditorCommand.cpp (revision 234266) >+++ Source/WebCore/editing/EditorCommand.cpp (working copy) >@@ -559,27 +559,27 @@ static bool executeJustifyRight(Frame& f > > static bool executeMakeTextWritingDirectionLeftToRight(Frame& frame, Event*, EditorCommandSource, const String&) > { >- RefPtr<MutableStyleProperties> style = MutableStyleProperties::create(); >+ auto style = MutableStyleProperties::create(); > style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); > style->setProperty(CSSPropertyDirection, CSSValueLtr); >- frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); >+ frame.editor().applyStyle(style.ptr(), EditActionSetWritingDirection); > return true; > } > > static bool executeMakeTextWritingDirectionNatural(Frame& frame, Event*, EditorCommandSource, const String&) > { >- RefPtr<MutableStyleProperties> style = MutableStyleProperties::create(); >+ auto style = MutableStyleProperties::create(); > style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); >- frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); >+ frame.editor().applyStyle(style.ptr(), EditActionSetWritingDirection); > return true; > } > > static bool executeMakeTextWritingDirectionRightToLeft(Frame& frame, Event*, EditorCommandSource, const String&) > { >- RefPtr<MutableStyleProperties> style = MutableStyleProperties::create(); >+ auto style = MutableStyleProperties::create(); > style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); > style->setProperty(CSSPropertyDirection, CSSValueRtl); >- frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); >+ frame.editor().applyStyle(style.ptr(), EditActionSetWritingDirection); > return true; > } > >Index: Source/WebCore/editing/InsertLineBreakCommand.cpp >=================================================================== >--- Source/WebCore/editing/InsertLineBreakCommand.cpp (revision 234266) >+++ Source/WebCore/editing/InsertLineBreakCommand.cpp (working copy) >@@ -149,7 +149,7 @@ void InsertLineBreakCommand::doApply() > // leaves and then comes back, new input will have the right style. > // FIXME: We shouldn't always apply the typing style to the line break here, > // see <rdar://problem/5794462>. >- applyStyle(typingStyle.get(), firstPositionInOrBeforeNode(nodeToInsert.get()), lastPositionInOrAfterNode(nodeToInsert.get())); >+ applyStyle(typingStyle.releaseNonNull(), firstPositionInOrBeforeNode(nodeToInsert.get()), lastPositionInOrAfterNode(nodeToInsert.get())); > // Even though this applyStyle operates on a Range, it still sets an endingSelection(). > // It tries to set a VisibleSelection around the content it operated on. So, that VisibleSelection > // will either (a) select the line break we inserted, or it will (b) be a caret just >Index: Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp >=================================================================== >--- Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp (revision 234266) >+++ Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp (working copy) >@@ -101,7 +101,7 @@ void InsertParagraphSeparatorCommand::ap > > m_style->prepareToApplyAt(endingSelection().start()); > if (!m_style->isEmpty()) >- applyStyle(m_style.get()); >+ applyStyle(m_style->copy()); > } > > bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Node* enclosingBlock) const >Index: Source/WebCore/editing/InsertTextCommand.cpp >=================================================================== >--- Source/WebCore/editing/InsertTextCommand.cpp (revision 234266) >+++ Source/WebCore/editing/InsertTextCommand.cpp (working copy) >@@ -227,7 +227,7 @@ void InsertTextCommand::doApply() > if (RefPtr<EditingStyle> typingStyle = frame().selection().typingStyle()) { > typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection); > if (!typingStyle->isEmpty()) >- applyStyle(typingStyle.get()); >+ applyStyle(typingStyle.releaseNonNull()); > } > > if (!m_selectInsertedText) >Index: Source/WebCore/editing/RemoveFormatCommand.cpp >=================================================================== >--- Source/WebCore/editing/RemoveFormatCommand.cpp (revision 234266) >+++ Source/WebCore/editing/RemoveFormatCommand.cpp (working copy) >@@ -83,13 +83,14 @@ void RemoveFormatCommand::doApply() > // Get the default style for this editable root, it's the style that we'll give the > // content that we're operating on. > Node* root = endingSelection().rootEditableElement(); >- RefPtr<EditingStyle> defaultStyle = EditingStyle::create(root); >+ >+ auto defaultStyle = EditingStyle::create(root); > > // We want to remove everything but transparent background. > // FIXME: We shouldn't access style(). > defaultStyle->style()->setProperty(CSSPropertyBackgroundColor, CSSValueTransparent); > >- applyCommandToComposite(ApplyStyleCommand::create(document(), defaultStyle.get(), isElementForRemoveFormatCommand, editingAction())); >+ applyCommandToComposite(ApplyStyleCommand::create(document(), WTFMove(defaultStyle), isElementForRemoveFormatCommand, editingAction())); > } > > } >Index: Source/WebCore/editing/ReplaceSelectionCommand.cpp >=================================================================== >--- Source/WebCore/editing/ReplaceSelectionCommand.cpp (revision 234266) >+++ Source/WebCore/editing/ReplaceSelectionCommand.cpp (working copy) >@@ -1386,7 +1386,7 @@ void ReplaceSelectionCommand::addSpacesF > } > } > >-void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositionToSelect) >+void ReplaceSelectionCommand::completeHTMLReplacement(const Position& lastPositionToSelect) > { > Position start = positionAtStartOfInsertedContent().deepEquivalent(); > Position end = positionAtEndOfInsertedContent().deepEquivalent(); >@@ -1399,7 +1399,7 @@ void ReplaceSelectionCommand::completeHT > > if (m_matchStyle) { > ASSERT(m_insertionStyle); >- applyStyle(m_insertionStyle.get(), start, end); >+ applyStyle(m_insertionStyle->copy(), start, end); > } > > if (lastPositionToSelect.isNotNull())
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
darin
:
review+
ews-watchlist
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188062
: 345850 |
345869