Skip to content

Commit

Permalink
Bug 1253678 - Rename mozilla::Function to mozilla::function. r=froydnj
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 60RPmEsYDN2

--HG--
extra : rebase_source : 9d0bebc7362af2778d123425c56ac20553d9303b
  • Loading branch information
bgirard committed Mar 11, 2016
1 parent 98f171e commit 52f227c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions dom/media/VideoUtils.cpp
Expand Up @@ -498,8 +498,8 @@ ParseCodecsString(const nsAString& aCodecs, nsTArray<nsString>& aOutCodecs)

static bool
CheckContentType(const nsAString& aContentType,
mozilla::Function<bool(const nsAString&)> aSubtypeFilter,
mozilla::Function<bool(const nsAString&)> aCodecFilter)
mozilla::function<bool(const nsAString&)> aSubtypeFilter,
mozilla::function<bool(const nsAString&)> aCodecFilter)
{
nsContentTypeParser parser(aContentType);
nsAutoString mimeType;
Expand Down
2 changes: 1 addition & 1 deletion gfx/2d/SFNTNameTable.h
Expand Up @@ -18,7 +18,7 @@ namespace gfx {
struct NameHeader;
struct NameRecord;

typedef Vector<Function<bool(const NameRecord*)>> NameRecordMatchers;
typedef Vector<function<bool(const NameRecord*)>> NameRecordMatchers;

class SFNTNameTable final
{
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/apz/util/APZCCallbackHelper.h
Expand Up @@ -22,7 +22,7 @@ template<class T> class nsCOMPtr;
namespace mozilla {
namespace layers {

typedef Function<void(uint64_t, const nsTArray<TouchBehaviorFlags>&)>
typedef function<void(uint64_t, const nsTArray<TouchBehaviorFlags>&)>
SetAllowedTouchBehaviorCallback;

/* This class contains some helper methods that facilitate implementing the
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/apz/util/APZEventState.h
Expand Up @@ -28,7 +28,7 @@ namespace layers {

class ActiveElementManager;

typedef Function<void(const ScrollableLayerGuid&,
typedef function<void(const ScrollableLayerGuid&,
uint64_t /* input block id */,
bool /* prevent default */)>
ContentReceivedInputBlockCallback;
Expand Down
6 changes: 5 additions & 1 deletion gfx/skia/skia/include/private/SkTLogic.h
Expand Up @@ -59,7 +59,11 @@ namespace std {
#define false_type FalseType
#define true_type TrueType

using mozilla::Function;
// If we have 'using mozilla::function', we're going to collide with
// 'std::function' on platforms that have it. Therefore we use a macro
// work around.
template<typename Signature>
using Function = mozilla::function<Signature>;
#define function Function
#endif
}
Expand Down
26 changes: 13 additions & 13 deletions mfbt/Function.h
Expand Up @@ -14,7 +14,7 @@
#include "mozilla/RefCounted.h"
#include "mozilla/RefPtr.h"

// |Function<Signature>| is a wrapper that can hold any type of callable
// |function<Signature>| is a wrapper that can hold any type of callable
// object that can be invoked in a way that's compatible with |Signature|.
// The standard "type erasure" technique is used to avoid the type of the
// wrapper depending on the concrete type of the wrapped callable.
Expand All @@ -29,7 +29,7 @@
// this is a function type; it's not used in any way other than serving as a
// vehicle to encode the return and argument types into a single type.
//
// |Function| is default-constructible. A default-constructed instance is
// |function| is default-constructible. A default-constructed instance is
// considered "empty". Invoking an empty instance is undefined behaviour.
// An empty instance can be populated with a callable by assigning to it.
//
Expand Down Expand Up @@ -129,45 +129,45 @@ class FunctionImpl<ReturnType(ThisType::*)(Args...) const,
// and |Arguments| in the definition of the specialization without having to
// introspect |Signature|.
template<typename Signature>
class Function;
class function;

template<typename ReturnType, typename... Arguments>
class Function<ReturnType(Arguments...)>
class function<ReturnType(Arguments...)>
{
public:
Function() {}
function() {}

// This constructor is implicit to match the interface of |std::function|.
template <typename Callable>
MOZ_IMPLICIT Function(const Callable& aCallable)
MOZ_IMPLICIT function(const Callable& aCallable)
: mImpl(new detail::FunctionImpl<Callable, ReturnType, Arguments...>(aCallable))
{}
MOZ_IMPLICIT Function(const Function& aFunction)
MOZ_IMPLICIT function(const function& aFunction)
: mImpl(aFunction.mImpl)
{}
MOZ_IMPLICIT Function(decltype(nullptr))
MOZ_IMPLICIT function(decltype(nullptr))
{}

// Move constructor and move assingment operator.
// These should be generated automatically, but MSVC doesn't do that yet.
Function(Function&& aOther) : mImpl(Move(aOther.mImpl)) {}
Function& operator=(Function&& aOther) {
function(function&& aOther) : mImpl(Move(aOther.mImpl)) {}
function& operator=(function&& aOther) {
mImpl = Move(aOther.mImpl);
return *this;
}

template <typename Callable>
Function& operator=(const Callable& aCallable)
function& operator=(const Callable& aCallable)
{
mImpl = new detail::FunctionImpl<Callable, ReturnType, Arguments...>(aCallable);
return *this;
}
Function& operator=(const Function& aFunction)
function& operator=(const function& aFunction)
{
mImpl = aFunction.mImpl;
return *this;
}
Function& operator=(decltype(nullptr))
function& operator=(decltype(nullptr))
{
mImpl = nullptr;
return *this;
Expand Down
20 changes: 10 additions & 10 deletions mfbt/tests/TestFunction.cpp
Expand Up @@ -7,7 +7,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/Function.h"

using mozilla::Function;
using mozilla::function;

#define CHECK(c) \
do { \
Expand Down Expand Up @@ -36,41 +36,41 @@ struct Incrementor {
static void
TestNonmemberFunction()
{
Function<int(int)> f = &increment;
function<int(int)> f = &increment;
CHECK(f(42) == 43);
}

static void
TestStaticMemberFunction()
{
Function<int(int)> f = &S::increment;
function<int(int)> f = &S::increment;
CHECK(f(42) == 43);
}

static void
TestFunctionObject()
{
Function<int(int)> f = Incrementor();
function<int(int)> f = Incrementor();
CHECK(f(42) == 43);
}

static void
TestLambda()
{
// Test non-capturing lambda
Function<int(int)> f = [](int arg){ return arg + 1; };
function<int(int)> f = [](int arg){ return arg + 1; };
CHECK(f(42) == 43);

// Test capturing lambda
int one = 1;
Function<int(int)> g = [one](int arg){ return arg + one; };
function<int(int)> g = [one](int arg){ return arg + one; };
CHECK(g(42) == 43);
}

static void
TestDefaultConstructionAndAssignmentLater()
{
Function<int(int)> f; // allowed
function<int(int)> f; // allowed
// Would get an assertion if we tried calling f now.
f = &increment;
CHECK(f(42) == 43);
Expand All @@ -79,7 +79,7 @@ TestDefaultConstructionAndAssignmentLater()
static void
TestReassignment()
{
Function<int(int)> f = &increment;
function<int(int)> f = &increment;
CHECK(f(42) == 43);
f = [](int arg){ return arg + 2; };
CHECK(f(42) == 44);
Expand All @@ -88,15 +88,15 @@ TestReassignment()
static void
TestMemberFunction()
{
Function<int(S&, int)> f = &S::decrement;
function<int(S&, int)> f = &S::decrement;
S s;
CHECK((f(s, 1) == 0));
}

static void
TestConstMemberFunction()
{
Function<int(const S*, int, int)> f = &S::sum;
function<int(const S*, int, int)> f = &S::sum;
const S s;
CHECK((f(&s, 1, 1) == 2));
}
Expand Down
2 changes: 1 addition & 1 deletion xpcom/base/NSPRLogModulesParser.cpp
Expand Up @@ -15,7 +15,7 @@ namespace mozilla {

void
NSPRLogModulesParser(const char* aLogModules,
Function<void(const char*, LogLevel)> aCallback)
function<void(const char*, LogLevel)> aCallback)
{
if (!aLogModules) {
return;
Expand Down
2 changes: 1 addition & 1 deletion xpcom/base/NSPRLogModulesParser.h
Expand Up @@ -17,6 +17,6 @@ namespace mozilla {
* @param aCallback The callback to invoke for each log module config entry.
*/
void NSPRLogModulesParser(const char* aLogModules,
Function<void(const char*, LogLevel)> aCallback);
function<void(const char*, LogLevel)> aCallback);

} // namespace mozilla

0 comments on commit 52f227c

Please sign in to comment.