Diff
Modified: trunk/Source/WTF/ChangeLog (155406 => 155407)
--- trunk/Source/WTF/ChangeLog 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/ChangeLog 2013-09-10 00:43:51 UTC (rev 155407)
@@ -1,5 +1,31 @@
2013-09-09 Anders Carlsson <[email protected]>
+ Introduce WTF::createOwned
+ https://bugs.webkit.org/show_bug.cgi?id=121059
+
+ Reviewed by Andreas Kling.
+
+ WTF::createOwned is a function template that does adoptPtr + new in a single function call,
+ with all the arguments being perfectly forwarded thanks to C++11.
+
+ Being forward-looking, createOwned returns an OwnPtr rather than a PassOwnPtr since the plan is
+ to get rid of PassOwnPtr and just use std::move instead.
+
+ * wtf/FilePrintStream.cpp:
+ * wtf/FilePrintStream.h:
+ * wtf/HashTable.h:
+ * wtf/ListHashSet.h:
+ * wtf/OwnPtr.h:
+ (WTF::OwnPtr::OwnPtr):
+ (WTF::createOwned):
+ (WTF::createThread):
+ (WTF::establishIdentifierForPthreadHandle):
+ (WTF::createThreadInternal):
+ (WTF::Collator::userDefault):
+ (WTF::Collator::userDefault):
+
+2013-09-09 Anders Carlsson <[email protected]>
+
Remove wtf/TypeTraits.h
https://bugs.webkit.org/show_bug.cgi?id=121047
Modified: trunk/Source/WTF/wtf/FilePrintStream.cpp (155406 => 155407)
--- trunk/Source/WTF/wtf/FilePrintStream.cpp 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/FilePrintStream.cpp 2013-09-10 00:43:51 UTC (rev 155407)
@@ -41,13 +41,13 @@
fclose(m_file);
}
-PassOwnPtr<FilePrintStream> FilePrintStream::open(const char* filename, const char* mode)
+OwnPtr<FilePrintStream> FilePrintStream::open(const char* filename, const char* mode)
{
FILE* file = fopen(filename, mode);
if (!file)
- return PassOwnPtr<FilePrintStream>();
-
- return adoptPtr(new FilePrintStream(file));
+ return nullptr;
+
+ return createOwned<FilePrintStream>(file);
}
void FilePrintStream::vprintf(const char* format, va_list argList)
Modified: trunk/Source/WTF/wtf/FilePrintStream.h (155406 => 155407)
--- trunk/Source/WTF/wtf/FilePrintStream.h 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/FilePrintStream.h 2013-09-10 00:43:51 UTC (rev 155407)
@@ -27,8 +27,8 @@
#define FilePrintStream_h
#include <stdio.h>
-#include <wtf/PassOwnPtr.h>
#include <wtf/PrintStream.h>
+#include <wtf/OwnPtr.h>
namespace WTF {
@@ -42,7 +42,7 @@
FilePrintStream(FILE*, AdoptionMode = Adopt);
virtual ~FilePrintStream();
- WTF_EXPORT_PRIVATE static PassOwnPtr<FilePrintStream> open(const char* filename, const char* mode);
+ WTF_EXPORT_PRIVATE static OwnPtr<FilePrintStream> open(const char* filename, const char* mode);
FILE* file() { return m_file; }
Modified: trunk/Source/WTF/wtf/HashTable.h (155406 => 155407)
--- trunk/Source/WTF/wtf/HashTable.h 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/HashTable.h 2013-09-10 00:43:51 UTC (rev 155407)
@@ -555,10 +555,10 @@
, m_deletedCount(0)
#if CHECK_HASHTABLE_ITERATORS
, m_iterators(0)
- , m_mutex(adoptPtr(new Mutex))
+ , m_mutex(createOwned<Mutex>())
#endif
#if DUMP_HASHTABLE_STATS_PER_TABLE
- , m_stats(adoptPtr(new Stats))
+ , m_stats(createOwned<Stats>())
#endif
{
}
@@ -1166,10 +1166,10 @@
, m_deletedCount(0)
#if CHECK_HASHTABLE_ITERATORS
, m_iterators(0)
- , m_mutex(adoptPtr(new Mutex))
+ , m_mutex(createOwned<Mutex>())
#endif
#if DUMP_HASHTABLE_STATS_PER_TABLE
- , m_stats(adoptPtr(new Stats(*other.m_stats)))
+ , m_stats(createOwned<Stats>(*other.m_stats))
#endif
{
// Copy the hash table the dumb way, by adding each element to the new table.
Modified: trunk/Source/WTF/wtf/ListHashSet.h (155406 => 155407)
--- trunk/Source/WTF/wtf/ListHashSet.h 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/ListHashSet.h 2013-09-10 00:43:51 UTC (rev 155407)
@@ -511,7 +511,7 @@
inline ListHashSet<T, inlineCapacity, U>::ListHashSet()
: m_head(0)
, m_tail(0)
- , m_allocator(adoptPtr(new NodeAllocator))
+ , m_allocator(createOwned<NodeAllocator>())
{
}
@@ -519,7 +519,7 @@
inline ListHashSet<T, inlineCapacity, U>::ListHashSet(const ListHashSet& other)
: m_head(0)
, m_tail(0)
- , m_allocator(adoptPtr(new NodeAllocator))
+ , m_allocator(createOwned<NodeAllocator>())
{
const_iterator end = other.end();
for (const_iterator it = other.begin(); it != end; ++it)
Modified: trunk/Source/WTF/wtf/OwnPtr.h (155406 => 155407)
--- trunk/Source/WTF/wtf/OwnPtr.h 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/OwnPtr.h 2013-09-10 00:43:51 UTC (rev 155407)
@@ -36,11 +36,6 @@
template<typename T> PassOwnPtr<T> adoptPtr(T*);
template<typename T> class OwnPtr {
-#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
- // If rvalue references are not supported, the copy constructor is
- // public so OwnPtr cannot be marked noncopyable. See note below.
- WTF_MAKE_NONCOPYABLE(OwnPtr);
-#endif
public:
typedef typename std::remove_pointer<T>::type ValueType;
typedef ValueType* PtrType;
@@ -91,6 +86,12 @@
void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); }
private:
+ explicit OwnPtr(PtrType ptr) : m_ptr(ptr) { }
+
+ template<typename U> friend OwnPtr<U> createOwned();
+ template<typename U, typename A1> friend OwnPtr<U> createOwned(A1&&);
+ template<typename U, typename A1, typename A2> friend OwnPtr<U> createOwned(A1&&, A2&&);
+
#if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
// If rvalue references are supported, noncopyable takes care of this.
OwnPtr& operator=(const OwnPtr&);
@@ -212,8 +213,27 @@
return p.get();
}
+template<typename T>
+inline OwnPtr<T> createOwned()
+{
+ return OwnPtr<T>(new T);
+}
+
+template<typename T, typename A1>
+inline OwnPtr<T> createOwned(A1&& a1)
+{
+ return OwnPtr<T>(new T(std::forward<A1>(a1)));
+}
+
+template<typename T, typename A1, typename A2>
+inline OwnPtr<T> createOwned(A1&& a1, A2&& a2)
+{
+ return OwnPtr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2)));
+}
+
} // namespace WTF
using WTF::OwnPtr;
+using WTF::createOwned;
#endif // WTF_OwnPtr_h
Modified: trunk/Source/WTF/wtf/Threading.cpp (155406 => 155407)
--- trunk/Source/WTF/wtf/Threading.cpp 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/Threading.cpp 2013-09-10 00:43:51 UTC (rev 155407)
@@ -116,7 +116,7 @@
ThreadIdentifier createThread(ThreadFunctionWithReturnValue entryPoint, void* data, const char* name)
{
- OwnPtr<ThreadFunctionWithReturnValueInvocation> invocation = adoptPtr(new ThreadFunctionWithReturnValueInvocation(entryPoint, data));
+ auto invocation = createOwned<ThreadFunctionWithReturnValueInvocation>(entryPoint, data);
// Balanced by adoptPtr() in compatEntryPoint.
return createThread(compatEntryPoint, invocation.leakPtr(), name);
@@ -136,7 +136,7 @@
ThreadIdentifier createThread(ThreadFunctionWithReturnValue entryPoint, void* data)
{
- OwnPtr<ThreadFunctionWithReturnValueInvocation> invocation = adoptPtr(new ThreadFunctionWithReturnValueInvocation(entryPoint, data));
+ auto invocation = createOwned<ThreadFunctionWithReturnValueInvocation>(entryPoint, data);
// Balanced by adoptPtr() in compatEntryPoint.
return createThread(compatEntryPoint, invocation.leakPtr(), 0);
Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (155406 => 155407)
--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp 2013-09-10 00:43:51 UTC (rev 155407)
@@ -179,7 +179,7 @@
ASSERT(!identifierByPthreadHandle(pthreadHandle));
MutexLocker locker(threadMapMutex());
static ThreadIdentifier identifierCount = 1;
- threadMap().add(identifierCount, adoptPtr(new PthreadState(pthreadHandle)));
+ threadMap().add(identifierCount, createOwned<PthreadState>(pthreadHandle).release());
return identifierCount++;
}
@@ -198,7 +198,7 @@
ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*)
{
- OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInvocation(entryPoint, data));
+ auto invocation = WTF::createOwned<ThreadFunctionInvocation>(entryPoint, data);
pthread_t threadHandle;
if (pthread_create(&threadHandle, 0, wtfThreadEntryPoint, invocation.get())) {
LOG_ERROR("Failed to create pthread at entry point %p with data %p", wtfThreadEntryPoint, invocation.get());
Modified: trunk/Source/WTF/wtf/unicode/Collator.h (155406 => 155407)
--- trunk/Source/WTF/wtf/unicode/Collator.h 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/unicode/Collator.h 2013-09-10 00:43:51 UTC (rev 155407)
@@ -30,7 +30,7 @@
#define WTF_Collator_h
#include <wtf/Noncopyable.h>
-#include <wtf/PassOwnPtr.h>
+#include <wtf/OwnPtr.h>
#include <wtf/unicode/Unicode.h>
#if USE(ICU_UNICODE) && !UCONFIG_NO_COLLATION
@@ -48,7 +48,7 @@
WTF_EXPORT_PRIVATE ~Collator();
WTF_EXPORT_PRIVATE void setOrderLowerFirst(bool);
- WTF_EXPORT_PRIVATE static PassOwnPtr<Collator> userDefault();
+ WTF_EXPORT_PRIVATE static OwnPtr<Collator> userDefault();
WTF_EXPORT_PRIVATE Result collate(const ::UChar*, size_t, const ::UChar*, size_t) const;
Modified: trunk/Source/WTF/wtf/unicode/CollatorDefault.cpp (155406 => 155407)
--- trunk/Source/WTF/wtf/unicode/CollatorDefault.cpp 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/unicode/CollatorDefault.cpp 2013-09-10 00:43:51 UTC (rev 155407)
@@ -45,9 +45,9 @@
{
}
-PassOwnPtr<Collator> Collator::userDefault()
+OwnPtr<Collator> Collator::userDefault()
{
- return adoptPtr(new Collator(0));
+ return createOwned<Collator>(0);
}
// A default implementation for platforms that lack Unicode-aware collation.
Modified: trunk/Source/WTF/wtf/unicode/icu/CollatorICU.cpp (155406 => 155407)
--- trunk/Source/WTF/wtf/unicode/icu/CollatorICU.cpp 2013-09-10 00:35:19 UTC (rev 155406)
+++ trunk/Source/WTF/wtf/unicode/icu/CollatorICU.cpp 2013-09-10 00:43:51 UTC (rev 155407)
@@ -58,7 +58,7 @@
{
}
-PassOwnPtr<Collator> Collator::userDefault()
+OwnPtr<Collator> Collator::userDefault()
{
#if OS(DARWIN) && USE(CF)
// Mac OS X doesn't set UNIX locale to match user-selected one, so ICU default doesn't work.
@@ -71,11 +71,11 @@
#endif
char buf[256];
if (!collationOrder)
- return adoptPtr(new Collator(""));
+ return createOwned<Collator>("");
CFStringGetCString(collationOrder, buf, sizeof(buf), kCFStringEncodingASCII);
- return adoptPtr(new Collator(buf));
+ return createOwned<Collator>(buf);
#else
- return adoptPtr(new Collator(0));
+ return createOwned<Collator>(static_cast<const char*>(0));
#endif
}