Skip to content

Commit

Permalink
Reduce use of CheckedPtr with non-stack variables
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267415

Reviewed by Brent Fulgham.

This tested as performance neutral on Speedometer 2 & 3.

* Source/WebCore/dom/ScriptedAnimationController.h:
* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::containsEndpoints):
* Source/WebCore/editing/FrameSelection.h:
* Source/WebCore/editing/RenderedPosition.h:
* Source/WebCore/editing/SpellChecker.h:

Canonical link: https://commits.webkit.org/272935@main
  • Loading branch information
cdumez committed Jan 11, 2024
1 parent 7e29032 commit d728765
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/dom/ScriptedAnimationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ScriptedAnimationController : public RefCounted<ScriptedAnimationControlle
};
Vector<CallbackData> m_callbackDataList;

CheckedPtr<Document> m_document;
WeakPtr<Document, WeakPtrImplWithEventTargetData> m_document;
CallbackId m_nextCallbackId { 0 };
int m_suspendCount { 0 };

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/editing/FrameSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2893,12 +2893,12 @@ void FrameSelection::setCaretColor(const Color& caretColor)

#endif // PLATFORM(IOS_FAMILY)

static bool containsEndpoints(const CheckedPtr<Document>& document, const std::optional<SimpleRange>& range)
static bool containsEndpoints(const WeakPtr<Document, WeakPtrImplWithEventTargetData>& document, const std::optional<SimpleRange>& range)
{
return document && range && document->contains(range->start.container) && document->contains(range->end.container);
}

static bool containsEndpoints(const CheckedPtr<Document>& document, const Range& liveRange)
static bool containsEndpoints(const WeakPtr<Document, WeakPtrImplWithEventTargetData>& document, const Range& liveRange)
{
// Only need to check the start container because live ranges enforce the invariant that start and end have a common ancestor.
return document && document->contains(liveRange.startContainer());
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/editing/FrameSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class FrameSelection final : private CaretBase, public CaretAnimationClient, pub
void updateAssociatedLiveRange();
LayoutRect localCaretRect() const final { return localCaretRectWithoutUpdate(); }

CheckedPtr<Document> m_document;
WeakPtr<Document, WeakPtrImplWithEventTargetData> m_document;
RefPtr<Range> m_associatedLiveRange;
std::optional<LayoutUnit> m_xPosForVerticalArrowNavigation;
VisibleSelection m_selection;
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/editing/RenderedPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "InlineIteratorBox.h"
#include "InlineIteratorLineBox.h"
#include "TextAffinity.h"
#include <wtf/WeakPtr.h>

namespace WebCore {

Expand Down Expand Up @@ -81,7 +82,7 @@ class RenderedPosition {
bool atLeftBoundaryOfBidiRun(ShouldMatchBidiLevel, unsigned char bidiLevelOfRun) const;
bool atRightBoundaryOfBidiRun(ShouldMatchBidiLevel, unsigned char bidiLevelOfRun) const;

CheckedPtr<const RenderObject> m_renderer;
SingleThreadWeakPtr<const RenderObject> m_renderer;
InlineIterator::LeafBoxIterator m_box;
unsigned m_offset { 0 };

Expand Down
7 changes: 3 additions & 4 deletions Source/WebCore/editing/SpellChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
#include "SimpleRange.h"
#include "TextChecking.h"
#include "Timer.h"
#include <wtf/CheckedPtr.h>
#include <wtf/Deque.h>
#include <wtf/WeakRef.h>
#include <wtf/WeakPtr.h>

namespace WebCore {

Expand Down Expand Up @@ -60,15 +59,15 @@ class SpellCheckRequest final : public TextCheckingRequest {

SpellCheckRequest(const SimpleRange& checkingRange, const SimpleRange& automaticReplacementRange, const SimpleRange& paragraphRange, const String&, OptionSet<TextCheckingType>, TextCheckingProcessType);

CheckedPtr<SpellChecker> m_checker;
SingleThreadWeakPtr<SpellChecker> m_checker;
SimpleRange m_checkingRange;
SimpleRange m_automaticReplacementRange;
SimpleRange m_paragraphRange;
RefPtr<Element> m_rootEditableElement;
TextCheckingRequestData m_requestData;
};

class SpellChecker : public CanMakeCheckedPtr {
class SpellChecker : public CanMakeSingleThreadWeakPtr<SpellChecker> {
WTF_MAKE_FAST_ALLOCATED;
public:
friend class SpellCheckRequest;
Expand Down

0 comments on commit d728765

Please sign in to comment.