Bug 27001 - Fix improper use of PassRefPtr<Node> to RefPtr<Node>
Summary: Fix improper use of PassRefPtr<Node> to RefPtr<Node>
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-06 14:13 PDT by David Kilzer (:ddkilzer)
Modified: 2009-07-06 17:59 PDT (History)
0 users

See Also:


Attachments
Patch v1 (3.10 KB, patch)
2009-07-06 14:13 PDT, David Kilzer (:ddkilzer)
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2009-07-06 14:13:41 PDT
Created attachment 32318 [details]
Patch v1

Fix improper use of PassRefPtr<Node> to RefPtr<Node>

Reviewed by NOBODY (OOPS!).

PassRefPtr<> should only be used for arguments to functions that take ownership of the object, or as return values from functions that relinquish ownership of the object.

* editing/Editor.cpp:
(WebCore::Editor::increaseSelectionListLevelOrdered): Changed stack-allocated PassRefPtr<Node> to RefPtr<Node> and call release() on returned object to prevent ref count churn.
(WebCore::Editor::increaseSelectionListLevelUnordered): Ditto.
Comment 1 Geoffrey Garen 2009-07-06 14:16:11 PDT
Comment on attachment 32318 [details]
Patch v1

>         (WebCore::Editor::increaseSelectionListLevelOrdered): Changed
>         stack-allocated PassRefPtr<Node> to RefPtr<Node> and call
>         release() on returned object to prevent ref count churn.

Technically, I don't think there would be refcount churn, since the default behavior of PassRefPtr is to give up its reference upon assignment:

        template <typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.releaseRef()) { }

However, this is still a good change for the style reasons you cited.
Comment 2 David Kilzer (:ddkilzer) 2009-07-06 17:55:45 PDT
(In reply to comment #1)
> (From update of attachment 32318 [details])
> >         (WebCore::Editor::increaseSelectionListLevelOrdered): Changed
> >         stack-allocated PassRefPtr<Node> to RefPtr<Node> and call
> >         release() on returned object to prevent ref count churn.
> 
> Technically, I don't think there would be refcount churn, since the default
> behavior of PassRefPtr is to give up its reference upon assignment:
> 
>         template <typename U> PassRefPtr(const PassRefPtr<U>& o) :
> m_ptr(o.releaseRef()) { }

I'll adjust the changelog entry.  (If you didn't call release(), though, and returned the RefPtr<Node> object, I do believe some ref count churn would be involved creating a PassRefPtr<Node> from a RefPtr<Node>.  That's what I was referring to when using release().)
Comment 3 David Kilzer (:ddkilzer) 2009-07-06 17:59:23 PDT
$ git svn dcommit
Committing to http://svn.webkit.org/repository/webkit/trunk ...
	M	WebCore/ChangeLog
	M	WebCore/editing/Editor.cpp
Committed r45577

http://trac.webkit.org/changeset/45577