Commit cf1c637d authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 8

Don't name a member small

Summary:
Because, if you aren't compiling with `WIN32_LEAN_AND_MEAN`, including `WinSock2.h` will result in `small` being `#define`'d as `char`. The best way to work around the issue is to simply change the name of the member to something else.
It would also have been possible to solve the problem by adding a section to `folly/portability/Windows.h`, but that would have required including that header in `folly/Function.h`, which there really is no reason to do.

Reviewed By: yfeldblum

Differential Revision: D3666417

fbshipit-source-id: 21c0363a4b77bb01e4ec20b2fc625c40729879c3
parent a0f8eed7
...@@ -242,13 +242,13 @@ enum class Op { MOVE, NUKE, FULL, HEAP }; ...@@ -242,13 +242,13 @@ enum class Op { MOVE, NUKE, FULL, HEAP };
union Data { union Data {
void* big; void* big;
std::aligned_storage<6 * sizeof(void*)>::type small; std::aligned_storage<6 * sizeof(void*)>::type tiny;
}; };
template <typename Fun, typename FunT = typename std::decay<Fun>::type> template <typename Fun, typename FunT = typename std::decay<Fun>::type>
using IsSmall = std::integral_constant< using IsSmall = std::integral_constant<
bool, bool,
(sizeof(FunT) <= sizeof(Data::small) && (sizeof(FunT) <= sizeof(Data::tiny) &&
// Same as is_nothrow_move_constructible, but w/ no template instantiation. // Same as is_nothrow_move_constructible, but w/ no template instantiation.
noexcept(FunT(std::declval<FunT&&>())) noexcept(FunT(std::declval<FunT&&>()))
)>; )>;
...@@ -288,7 +288,7 @@ struct FunctionTraits<ReturnType(Args...)> { ...@@ -288,7 +288,7 @@ struct FunctionTraits<ReturnType(Args...)> {
template <typename Fun> template <typename Fun>
static ReturnType callSmall(Data& p, Args&&... args) { static ReturnType callSmall(Data& p, Args&&... args) {
return static_cast<ReturnType>((*static_cast<Fun*>( return static_cast<ReturnType>((*static_cast<Fun*>(
static_cast<void*>(&p.small)))(static_cast<Args&&>(args)...)); static_cast<void*>(&p.tiny)))(static_cast<Args&&>(args)...));
} }
template <typename Fun> template <typename Fun>
...@@ -329,7 +329,7 @@ struct FunctionTraits<ReturnType(Args...) const> { ...@@ -329,7 +329,7 @@ struct FunctionTraits<ReturnType(Args...) const> {
template <typename Fun> template <typename Fun>
static ReturnType callSmall(Data& p, Args&&... args) { static ReturnType callSmall(Data& p, Args&&... args) {
return static_cast<ReturnType>((*static_cast<const Fun*>( return static_cast<ReturnType>((*static_cast<const Fun*>(
static_cast<void*>(&p.small)))(static_cast<Args&&>(args)...)); static_cast<void*>(&p.tiny)))(static_cast<Args&&>(args)...));
} }
template <typename Fun> template <typename Fun>
...@@ -359,11 +359,11 @@ template <typename Fun> ...@@ -359,11 +359,11 @@ template <typename Fun>
bool execSmall(Op o, Data* src, Data* dst) { bool execSmall(Op o, Data* src, Data* dst) {
switch (o) { switch (o) {
case Op::MOVE: case Op::MOVE:
::new (static_cast<void*>(&dst->small)) ::new (static_cast<void*>(&dst->tiny))
Fun(std::move(*static_cast<Fun*>(static_cast<void*>(&src->small)))); Fun(std::move(*static_cast<Fun*>(static_cast<void*>(&src->tiny))));
FOLLY_FALLTHROUGH; FOLLY_FALLTHROUGH;
case Op::NUKE: case Op::NUKE:
static_cast<Fun*>(static_cast<void*>(&src->small))->~Fun(); static_cast<Fun*>(static_cast<void*>(&src->tiny))->~Fun();
break; break;
case Op::FULL: case Op::FULL:
return true; return true;
...@@ -433,7 +433,7 @@ class Function final : private detail::function::FunctionTraits<FunctionType> { ...@@ -433,7 +433,7 @@ class Function final : private detail::function::FunctionTraits<FunctionType> {
Function(Fun&& fun, SmallTag) noexcept { Function(Fun&& fun, SmallTag) noexcept {
using FunT = typename std::decay<Fun>::type; using FunT = typename std::decay<Fun>::type;
if (!detail::function::isNullPtrFn(fun)) { if (!detail::function::isNullPtrFn(fun)) {
::new (static_cast<void*>(&data_.small)) FunT(static_cast<Fun&&>(fun)); ::new (static_cast<void*>(&data_.tiny)) FunT(static_cast<Fun&&>(fun));
call_ = &Traits::template callSmall<FunT>; call_ = &Traits::template callSmall<FunT>;
exec_ = &detail::function::execSmall<FunT>; exec_ = &detail::function::execSmall<FunT>;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment