Diff
Modified: trunk/Source/WTF/ChangeLog (218463 => 218464)
--- trunk/Source/WTF/ChangeLog 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/ChangeLog 2017-06-18 19:49:12 UTC (rev 218464)
@@ -1,3 +1,33 @@
+2017-06-18 Chris Dumez <[email protected]>
+
+ Use WTF::Function instead of std::function in WTF/
+ https://bugs.webkit.org/show_bug.cgi?id=173519
+
+ Reviewed by Sam Weinig.
+
+ Use WTF::Function instead of std::function in WTF/ to avoid
+ copying.
+
+ * wtf/Brigand.h:
+ * wtf/Condition.h:
+ * wtf/Expected.h:
+ * wtf/FunctionDispatcher.h:
+ * wtf/MainThread.h:
+ * wtf/MemoryPressureHandler.h:
+ (WTF::MemoryPressureHandler::setMemoryKillCallback):
+ (WTF::MemoryPressureHandler::setMemoryPressureStatusChangedCallback):
+ (WTF::MemoryPressureHandler::setDidExceedInactiveLimitWhileActiveCallback):
+ * wtf/Optional.h:
+ * wtf/ParkingLot.h:
+ * wtf/RefCounter.h:
+ (WTF::RefCounter<T>::RefCounter):
+ * wtf/WorkQueue.h:
+ * wtf/linux/MemoryPressureHandlerLinux.cpp:
+ (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller):
+ * wtf/text/WTFString.cpp:
+ (WTF::String::split):
+ * wtf/text/WTFString.h:
+
2017-06-16 Alex Christensen <[email protected]>
Fix Mac CMake build.
Modified: trunk/Source/WTF/wtf/Brigand.h (218463 => 218464)
--- trunk/Source/WTF/wtf/Brigand.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/Brigand.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -51,7 +51,6 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
-#include <functional>
#include <initializer_list>
#include <tuple>
#include <type_traits>
Modified: trunk/Source/WTF/wtf/Condition.h (218463 => 218464)
--- trunk/Source/WTF/wtf/Condition.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/Condition.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -26,7 +26,6 @@
#ifndef WTF_Condition_h
#define WTF_Condition_h
-#include <functional>
#include <wtf/CurrentTime.h>
#include <wtf/Noncopyable.h>
#include <wtf/ParkingLot.h>
Modified: trunk/Source/WTF/wtf/Expected.h (218463 => 218464)
--- trunk/Source/WTF/wtf/Expected.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/Expected.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -29,7 +29,6 @@
#pragma once
#include <cstdlib>
-#include <functional>
#include <initializer_list>
#include <type_traits>
#include <utility>
Modified: trunk/Source/WTF/wtf/FunctionDispatcher.h (218463 => 218464)
--- trunk/Source/WTF/wtf/FunctionDispatcher.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/FunctionDispatcher.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -26,7 +26,6 @@
#ifndef FunctionDispatcher_h
#define FunctionDispatcher_h
-#include <functional>
#include <wtf/Function.h>
#include <wtf/ThreadSafeRefCounted.h>
Modified: trunk/Source/WTF/wtf/MainThread.h (218463 => 218464)
--- trunk/Source/WTF/wtf/MainThread.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/MainThread.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -30,7 +30,6 @@
#ifndef MainThread_h
#define MainThread_h
-#include <functional>
#include <stdint.h>
#include <wtf/Function.h>
#include <wtf/Optional.h>
Modified: trunk/Source/WTF/wtf/MemoryPressureHandler.h (218463 => 218464)
--- trunk/Source/WTF/wtf/MemoryPressureHandler.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -28,9 +28,9 @@
#include <atomic>
#include <ctime>
-#include <functional>
#include <wtf/FastMalloc.h>
#include <wtf/Forward.h>
+#include <wtf/Function.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/Optional.h>
#include <wtf/RunLoop.h>
@@ -59,7 +59,7 @@
enum class Critical { No, Yes };
enum class Synchronous { No, Yes };
-typedef std::function<void(Critical, Synchronous)> LowMemoryHandler;
+typedef WTF::Function<void(Critical, Synchronous)> LowMemoryHandler;
class MemoryPressureHandler {
friend class WTF::NeverDestroyed<MemoryPressureHandler>;
@@ -70,9 +70,9 @@
WTF_EXPORT_PRIVATE void setShouldUsePeriodicMemoryMonitor(bool);
- void setMemoryKillCallback(WTF::Function<void()> function) { m_memoryKillCallback = WTFMove(function); }
- void setMemoryPressureStatusChangedCallback(WTF::Function<void(bool)> function) { m_memoryPressureStatusChangedCallback = WTFMove(function); }
- void setDidExceedInactiveLimitWhileActiveCallback(WTF::Function<void()> function) { m_didExceedInactiveLimitWhileActiveCallback = WTFMove(function); }
+ void setMemoryKillCallback(WTF::Function<void()>&& function) { m_memoryKillCallback = WTFMove(function); }
+ void setMemoryPressureStatusChangedCallback(WTF::Function<void(bool)>&& function) { m_memoryPressureStatusChangedCallback = WTFMove(function); }
+ void setDidExceedInactiveLimitWhileActiveCallback(WTF::Function<void()>&& function) { m_didExceedInactiveLimitWhileActiveCallback = WTFMove(function); }
void setLowMemoryHandler(LowMemoryHandler&& handler)
{
@@ -172,7 +172,7 @@
class EventFDPoller {
WTF_MAKE_NONCOPYABLE(EventFDPoller); WTF_MAKE_FAST_ALLOCATED;
public:
- EventFDPoller(int fd, std::function<void ()>&& notifyHandler);
+ EventFDPoller(int fd, WTF::Function<void ()>&& notifyHandler);
~EventFDPoller();
private:
@@ -179,7 +179,7 @@
void readAndNotify() const;
std::optional<int> m_fd;
- std::function<void ()> m_notifyHandler;
+ WTF::Function<void ()> m_notifyHandler;
#if USE(GLIB)
GRefPtr<GSource> m_source;
#else
Modified: trunk/Source/WTF/wtf/Optional.h (218463 => 218464)
--- trunk/Source/WTF/wtf/Optional.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/Optional.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -41,7 +41,6 @@
# include <type_traits>
# include <initializer_list>
# include <cassert>
-# include <functional>
# include <string>
# include <stdexcept>
# include <wtf/Assertions.h>
Modified: trunk/Source/WTF/wtf/ParkingLot.h (218463 => 218464)
--- trunk/Source/WTF/wtf/ParkingLot.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/ParkingLot.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -26,7 +26,6 @@
#ifndef WTF_ParkingLot_h
#define WTF_ParkingLot_h
-#include <functional>
#include <wtf/Atomics.h>
#include <wtf/ScopedLambda.h>
#include <wtf/Threading.h>
Modified: trunk/Source/WTF/wtf/RefCounter.h (218463 => 218464)
--- trunk/Source/WTF/wtf/RefCounter.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/RefCounter.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -26,7 +26,7 @@
#ifndef RefCounter_h
#define RefCounter_h
-#include <functional>
+#include <wtf/Function.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
@@ -59,9 +59,9 @@
public:
using Token = RefPtr<Count>;
- using ValueChangeFunction = std::function<void (RefCounterEvent)>;
+ using ValueChangeFunction = WTF::Function<void (RefCounterEvent)>;
- RefCounter(ValueChangeFunction = nullptr);
+ RefCounter(ValueChangeFunction&& = nullptr);
~RefCounter();
Token count() const
@@ -105,8 +105,8 @@
}
template<typename T>
-inline RefCounter<T>::RefCounter(ValueChangeFunction valueDidChange)
- : m_valueDidChange(valueDidChange)
+inline RefCounter<T>::RefCounter(ValueChangeFunction&& valueDidChange)
+ : m_valueDidChange(WTFMove(valueDidChange))
, m_count(new Count(*this))
{
}
Modified: trunk/Source/WTF/wtf/WorkQueue.h (218463 => 218464)
--- trunk/Source/WTF/wtf/WorkQueue.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/WorkQueue.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -27,7 +27,6 @@
#ifndef WorkQueue_h
#define WorkQueue_h
-#include <functional>
#include <wtf/Forward.h>
#include <wtf/FunctionDispatcher.h>
#include <wtf/RefCounted.h>
Modified: trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp (218463 => 218464)
--- trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/linux/MemoryPressureHandlerLinux.cpp 2017-06-18 19:49:12 UTC (rev 218464)
@@ -99,7 +99,7 @@
};
#endif
-MemoryPressureHandler::EventFDPoller::EventFDPoller(int fd, std::function<void ()>&& notifyHandler)
+MemoryPressureHandler::EventFDPoller::EventFDPoller(int fd, WTF::Function<void ()>&& notifyHandler)
: m_fd(fd)
, m_notifyHandler(WTFMove(notifyHandler))
{
Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (218463 => 218464)
--- trunk/Source/WTF/wtf/text/WTFString.cpp 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp 2017-06-18 19:49:12 UTC (rev 218464)
@@ -743,7 +743,7 @@
result.append(substring(startPos));
}
-void String::split(UChar separator, bool allowEmptyEntries, SplitFunctor&& functor) const
+void String::split(UChar separator, bool allowEmptyEntries, const SplitFunctor& functor) const
{
StringView view(*this);
Modified: trunk/Source/WTF/wtf/text/WTFString.h (218463 => 218464)
--- trunk/Source/WTF/wtf/text/WTFString.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -25,8 +25,7 @@
// This file would be called String.h, but that conflicts with <string.h>
// on systems without case-sensitive file systems.
-#include <functional>
-
+#include <wtf/Function.h>
#include <wtf/text/ASCIIFastPath.h>
#include <wtf/text/IntegerToStringConversion.h>
#include <wtf/text/StringImpl.h>
@@ -367,8 +366,8 @@
split(separator, false, result);
}
- using SplitFunctor = std::function<void(const StringView&)>;
- WTF_EXPORT_STRING_API void split(UChar separator, bool allowEmptyEntries, SplitFunctor&&) const;
+ using SplitFunctor = WTF::Function<void(const StringView&)>;
+ WTF_EXPORT_STRING_API void split(UChar separator, bool allowEmptyEntries, const SplitFunctor&) const;
WTF_EXPORT_STRING_API void split(UChar separator, bool allowEmptyEntries, Vector<String>& result) const;
void split(UChar separator, Vector<String>& result) const
{
Modified: trunk/Source/WebCore/ChangeLog (218463 => 218464)
--- trunk/Source/WebCore/ChangeLog 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WebCore/ChangeLog 2017-06-18 19:49:12 UTC (rev 218464)
@@ -1,3 +1,26 @@
+2017-06-18 Chris Dumez <[email protected]>
+
+ Use WTF::Function instead of std::function in WTF/
+ https://bugs.webkit.org/show_bug.cgi?id=173519
+
+ Reviewed by Sam Weinig.
+
+ Replace a few uses of std::function with WTF::Function in WebCore/
+ as well. It was either this or including <functional> and I decided
+ it made more sense to port the code.
+
+ * platform/graphics/FontSelectionAlgorithm.h:
+ (WebCore::FontSelectionAlgorithm::iterateActiveCapabilitiesWithReturn):
+ * platform/mediastream/MediaConstraints.cpp:
+ (WebCore::StringConstraint::find):
+ (WebCore::MediaTrackConstraintSetMap::forEach):
+ (WebCore::MediaTrackConstraintSetMap::filter):
+ (WebCore::MediaConstraints::isConstraintSet):
+ * platform/mediastream/MediaConstraints.h:
+ (WebCore::NumericConstraint::find):
+ * platform/mediastream/RealtimeMediaSource.cpp:
+ (WebCore::RealtimeMediaSource::applyConstraint):
+
2017-06-18 Jer Noble <[email protected]>
[MSE] Seeking or entering fullscreen can cause extreme CPU usage
Modified: trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h (218463 => 218464)
--- trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -26,6 +26,7 @@
#pragma once
#include "TextFlags.h"
+#include <wtf/Function.h>
#include <wtf/GetPtr.h>
#include <wtf/Hasher.h>
#include <wtf/NeverDestroyed.h>
@@ -513,10 +514,10 @@
private:
template <typename T>
- using IterateActiveCapabilitiesWithReturnCallback = std::function<std::optional<T>(FontSelectionCapabilities, size_t)>;
+ using IterateActiveCapabilitiesWithReturnCallback = WTF::Function<std::optional<T>(FontSelectionCapabilities, size_t)>;
template <typename T>
- inline std::optional<T> iterateActiveCapabilitiesWithReturn(IterateActiveCapabilitiesWithReturnCallback<T> callback)
+ inline std::optional<T> iterateActiveCapabilitiesWithReturn(const IterateActiveCapabilitiesWithReturnCallback<T>& callback)
{
for (size_t i = 0; i < m_capabilities.size(); ++i) {
if (!m_filter[i])
Modified: trunk/Source/WebCore/platform/mediastream/MediaConstraints.cpp (218463 => 218464)
--- trunk/Source/WebCore/platform/mediastream/MediaConstraints.cpp 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WebCore/platform/mediastream/MediaConstraints.cpp 2017-06-18 19:49:12 UTC (rev 218464)
@@ -38,7 +38,7 @@
namespace WebCore {
-const String& StringConstraint::find(std::function<bool(const String&)> filter) const
+const String& StringConstraint::find(const WTF::Function<bool(const String&)>& filter) const
{
for (auto& constraint : m_exact) {
if (filter(constraint))
@@ -182,15 +182,15 @@
return nullptr;
}
-void MediaTrackConstraintSetMap::forEach(std::function<void(const MediaConstraint&)> callback) const
+void MediaTrackConstraintSetMap::forEach(WTF::Function<void(const MediaConstraint&)>&& callback) const
{
- filter([callback] (const MediaConstraint& constraint) mutable {
+ filter([callback = WTFMove(callback)] (const MediaConstraint& constraint) mutable {
callback(constraint);
return false;
});
}
-void MediaTrackConstraintSetMap::filter(std::function<bool(const MediaConstraint&)> callback) const
+void MediaTrackConstraintSetMap::filter(const WTF::Function<bool(const MediaConstraint&)>& callback) const
{
if (m_width && !m_width->isEmpty() && callback(*m_width))
return;
@@ -363,7 +363,7 @@
}
}
-bool MediaConstraints::isConstraintSet(std::function<bool(const MediaTrackConstraintSetMap&)>&& callback)
+bool MediaConstraints::isConstraintSet(const WTF::Function<bool(const MediaTrackConstraintSetMap&)>& callback)
{
if (callback(mandatoryConstraints))
return true;
Modified: trunk/Source/WebCore/platform/mediastream/MediaConstraints.h (218463 => 218464)
--- trunk/Source/WebCore/platform/mediastream/MediaConstraints.h 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WebCore/platform/mediastream/MediaConstraints.h 2017-06-18 19:49:12 UTC (rev 218464)
@@ -35,6 +35,7 @@
#include "RealtimeMediaSourceSupportedConstraints.h"
#include <cstdlib>
+#include <wtf/Function.h>
#include <wtf/Vector.h>
namespace WebCore {
@@ -220,7 +221,7 @@
return true;
}
- ValueType find(std::function<bool(ValueType)> function) const
+ ValueType find(const WTF::Function<bool(ValueType)>& function) const
{
if (m_min && function(m_min.value()))
return m_min.value();
@@ -525,7 +526,7 @@
double fitnessDistance(const String&) const;
double fitnessDistance(const Vector<String>&) const;
- const String& find(std::function<bool(const String&)>) const;
+ const String& find(const WTF::Function<bool(const String&)>&) const;
bool isEmpty() const { return m_exact.isEmpty() && m_ideal.isEmpty(); }
bool isMandatory() const { return !m_exact.isEmpty(); }
@@ -572,8 +573,8 @@
class MediaTrackConstraintSetMap {
public:
- WEBCORE_EXPORT void forEach(std::function<void(const MediaConstraint&)>) const;
- void filter(std::function<bool(const MediaConstraint&)>) const;
+ WEBCORE_EXPORT void forEach(WTF::Function<void(const MediaConstraint&)>&&) const;
+ void filter(const WTF::Function<bool(const MediaConstraint&)>&) const;
bool isEmpty() const;
WEBCORE_EXPORT size_t size() const;
@@ -806,7 +807,7 @@
struct MediaConstraints {
void setDefaultVideoConstraints();
- bool isConstraintSet(std::function<bool(const MediaTrackConstraintSetMap&)>&&);
+ bool isConstraintSet(const WTF::Function<bool(const MediaTrackConstraintSetMap&)>&);
MediaTrackConstraintSetMap mandatoryConstraints;
Vector<MediaTrackConstraintSetMap> advancedConstraints;
Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp (218463 => 218464)
--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp 2017-06-18 15:55:55 UTC (rev 218463)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp 2017-06-18 19:49:12 UTC (rev 218464)
@@ -502,7 +502,7 @@
return false;
};
- auto modeString = downcast<StringConstraint>(constraint).find(filter);
+ auto modeString = downcast<StringConstraint>(constraint).find(WTFMove(filter));
if (!modeString.isEmpty())
setFacingMode(RealtimeMediaSourceSettings::videoFacingModeEnum(modeString));
break;