Closed Bug 1428747 Opened 7 years ago Closed 7 years ago

Make EditorBase::GetDOMEventTarget() to return EventTarget* and GetFocusedContent() return nsIContent*

Categories

(Core :: DOM: Editor, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox59 --- fixed

People

(Reporter: smaug, Assigned: smaug)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

We're going too much AddRefing and Releasing in hot code paths.
Assignee: nobody → bugs
I changed only the callers which looked safe to use raw pointer. remote: View your change here: remote: https://hg.mozilla.org/try/rev/e1e886d2d8b2afa756ba865eb39b23e6f816dd03 remote: remote: Follow the progress of your build on Treeherder: remote: https://treeherder.mozilla.org/#/jobs?repo=try&revision=e1e886d2d8b2afa756ba865eb39b23e6f816dd03 remote: recorded changegroup in replication log in 0.053s
Attachment #8940750 - Flags: review?(masayuki)
Comment on attachment 8940750 [details] [diff] [review] editor_tweaks.diff > already_AddRefed<nsIContent> > EditorBase::GetFocusedContentForIME() > { >- return GetFocusedContent(); >+ nsCOMPtr<nsIContent> content = GetFocusedContent(); >+ return content.forget(); Although looks like that no callers of GetFocusedContentForIME() requires strong pointer. But it's fine to keep it. >-already_AddRefed<nsIContent> >+nsIContent* > HTMLEditor::GetFocusedContent() > { > nsFocusManager* fm = nsFocusManager::GetFocusManager(); > NS_ENSURE_TRUE(fm, nullptr); > > nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedContent(); > > nsCOMPtr<nsIDocument> document = GetDocument(); > if (NS_WARN_IF(!document)) { > return nullptr; > } > bool inDesignMode = document->HasFlag(NODE_IS_EDITABLE); > if (!focusedContent) { > // in designMode, nobody gets focus in most cases. > if (inDesignMode && OurWindowHasFocus()) { > nsCOMPtr<nsIContent> rootContent = document->GetRootElement(); >- return rootContent.forget(); >+ return rootContent.get(); nsIDocument::GetRootElement() returns raw pointer. https://searchfox.org/mozilla-central/rev/cf149b7b63ff97023e28723167725e38cf5df757/dom/base/nsDocument.cpp#4400-4401 So, this can be just: return document->GetRootElement(); >-already_AddRefed<EventTarget> >+EventTarget* > HTMLEditor::GetDOMEventTarget() > { > // Don't use getDocument here, because we have no way of knowing > // whether Init() was ever called. So we need to get the document > // ourselves, if it exists. > MOZ_ASSERT(IsInitialized(), "The HTMLEditor has not been initialized yet"); > nsCOMPtr<mozilla::dom::EventTarget> target = GetDocument(); >- return target.forget(); >+ return target; Although, out of scope of this bug. We can make GetDocument() return raw pointer now. It used to retrieving from weak ptr, but now, mDocument is nsCOMPtr, so, current implementation of it doesn't make sense. https://searchfox.org/mozilla-central/rev/cf149b7b63ff97023e28723167725e38cf5df757/editor/libeditor/EditorBase.cpp#596-597,599-600
Attachment #8940750 - Flags: review?(masayuki) → review+
Changed that GetRootElement case.
Pushed by opettay@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/9bcdad9d7f43 Make EditorBase::GetDOMEventTarget() to return EventTarget* and GetFocusedContent() return nsIContent* in order to optimize out some AddRef/Release calls, r=masayuki
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: