Add PassRef and createRefCounted so we can improve creation of RefCounted objects
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Oct 2013 17:18:05 +0000 (17:18 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Oct 2013 17:18:05 +0000 (17:18 +0000)
commit3a2b631eb700fcf5576a8dc8025be4c2ea9cb827
treecf1d725bc70689a816e2df75b8f99ed35b2779f2
parentb085d28c1807de4f3361d02c30d13c7f947e7ff1
Add PassRef and createRefCounted so we can improve creation of RefCounted objects
https://bugs.webkit.org/show_bug.cgi?id=122904

Reviewed by Anders Carlsson.

Source/WTF:

* GNUmakefile.list.am: Added PassRef.h.
* WTF.vcxproj/WTF.vcxproj: Ditto.
* WTF.vcxproj/WTF.vcxproj.filters: Ditto.
* WTF.xcodeproj/project.pbxproj: Ditto.
* wtf/CMakeLists.txt: Ditto.

* wtf/Forward.h: Added PassRef. Also re-sorted and un-indented to match what
the style-checking script expects.

* wtf/PassRef.h: Added. Includes the createRefCounted function template, which
is analogous to make_unique, but is for reference counted objects, and also
assumes that new will never return null. Also includes an overload of adoptRef
that takes a reference rather than a pointer.

* wtf/PassRefPtr.h: Include "PassRef.h" so we can share the adopted function.
Got rid of declarations that duplicate ones in there.
(WTF::refIfNotNull): Use nullptr.
(WTF::derefIfNotNull): Use nullptr.
(WTF::PassRefPtr::PassRefPtr): Use nullptr. Added an overload that takes a PassRef.
(WTF::PassRefPtr::operator UnspecifiedBoolType): Use nullptr.
(WTF::PassRefPtr::operator=): Made this deleted instead of compile time assertion.
(WTF::PassRefPtr::PassRefPtr): Made adopting constructor use an adopt tag instead
of an unused boolean.
(WTF::PassRefPtr::leakRef): Use nullptr.
(WTF::adoptRef): Use the adopt tag.

* wtf/Ref.h: Use Noncopyable instead of rolling our own.
(WTF::Ref::Ref): Add an overload that takes a PassRef.
(WTF::Ref::operator=): Ditto.

* wtf/RefPtr.h: Removed unneeded forward declaration of PassRefPtr.
(WTF::RefPtr::RefPtr): Use nullptr. Added overload that takes a PassRef.
(WTF::RefPtr::release): Use nullptr.
(WTF::RefPtr::operator UnspecifiedBoolType): Use nullptr.
(WTF::RefPtr::operator=): Added overload that takes a PassRef.
(WTF::RefPtr::clear): Use nullptr.

* wtf/StdLibExtras.h: Added inline keyword to isPointerTypeAlignmentOkay,
reinterpret_cast_ptr, and make_unique. Seems like a simple oversight that these
were missing before.

Tools:

* TestWebKitAPI/Tests/WTF/Ref.cpp: Added some basic tests for adoptRef and PassRef.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157520 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WTF/ChangeLog
Source/WTF/GNUmakefile.list.am
Source/WTF/WTF.vcxproj/WTF.vcxproj
Source/WTF/WTF.vcxproj/WTF.vcxproj.filters
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/Forward.h
Source/WTF/wtf/PassRef.h [new file with mode: 0644]
Source/WTF/wtf/PassRefPtr.h
Source/WTF/wtf/Ref.h
Source/WTF/wtf/RefPtr.h
Source/WTF/wtf/StdLibExtras.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/Ref.cpp