Title: [203236] trunk/Source/WTF
- Revision
- 203236
- Author
- [email protected]
- Date
- 2016-07-14 12:45:22 -0700 (Thu, 14 Jul 2016)
Log Message
Avoid an extra heap allocation when dispatching Functions to WorkQueue
https://bugs.webkit.org/show_bug.cgi?id=158367
Reviewed by Anders Carlsson.
Avoid an extra heap allocation when dispatching Functions to WorkQueue
by adding leakCallable() / adoptCallable() functions to Function.
* wtf/Function.h:
* wtf/cocoa/WorkQueueCocoa.cpp:
(WTF::WorkQueue::dispatch):
(WTF::WorkQueue::dispatchAfter):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (203235 => 203236)
--- trunk/Source/WTF/ChangeLog 2016-07-14 19:32:24 UTC (rev 203235)
+++ trunk/Source/WTF/ChangeLog 2016-07-14 19:45:22 UTC (rev 203236)
@@ -1,3 +1,18 @@
+2016-07-14 Chris Dumez <[email protected]>
+
+ Avoid an extra heap allocation when dispatching Functions to WorkQueue
+ https://bugs.webkit.org/show_bug.cgi?id=158367
+
+ Reviewed by Anders Carlsson.
+
+ Avoid an extra heap allocation when dispatching Functions to WorkQueue
+ by adding leakCallable() / adoptCallable() functions to Function.
+
+ * wtf/Function.h:
+ * wtf/cocoa/WorkQueueCocoa.cpp:
+ (WTF::WorkQueue::dispatch):
+ (WTF::WorkQueue::dispatchAfter):
+
2016-07-13 Myles C. Maxfield <[email protected]>
Addressing post-review comments after r203119
Modified: trunk/Source/WTF/wtf/Function.h (203235 => 203236)
--- trunk/Source/WTF/wtf/Function.h 2016-07-14 19:32:24 UTC (rev 203235)
+++ trunk/Source/WTF/wtf/Function.h 2016-07-14 19:45:22 UTC (rev 203236)
@@ -66,7 +66,6 @@
return *this;
}
-private:
class CallableWrapperBase {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -75,6 +74,19 @@
virtual Out call(In...) = 0;
};
+ CallableWrapperBase* leakCallable() WARN_UNUSED_RETURN
+ {
+ return m_callableWrapper.release();
+ }
+
+ static Function adoptCallable(CallableWrapperBase* callable)
+ {
+ Function function;
+ function.m_callableWrapper.reset(callable);
+ return function;
+ }
+
+private:
template<typename CallableType>
class CallableWrapper : public CallableWrapperBase {
public:
Modified: trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp (203235 => 203236)
--- trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp 2016-07-14 19:32:24 UTC (rev 203235)
+++ trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp 2016-07-14 19:45:22 UTC (rev 203236)
@@ -31,10 +31,10 @@
void WorkQueue::dispatch(Function<void ()>&& function)
{
ref();
- auto* functionPtr = new Function<void ()>(WTFMove(function));
+ auto* callable = function.leakCallable();
dispatch_async(m_dispatchQueue, ^{
- (*functionPtr)();
- delete functionPtr;
+ auto function = Function<void ()>::adoptCallable(callable);
+ function();
deref();
});
}
@@ -42,10 +42,10 @@
void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, Function<void ()>&& function)
{
ref();
- auto* functionPtr = new Function<void ()>(WTFMove(function));
+ auto* callable = function.leakCallable();
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, ^{
- (*functionPtr)();
- delete functionPtr;
+ auto function = Function<void ()>::adoptCallable(callable);
+ function();
deref();
});
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes