Skip to content

Commit

Permalink
demonomorphize some cases of dependent empty lambdas
Browse files Browse the repository at this point in the history
Summary: Callers are widely-instantiated and callees are instantiated on the lambdas. We can reduce the number and build size of instantiations by choosing a common noop function instead of a dependent empty lambda in these cases.

Reviewed By: DenisYaroshevskiy

Differential Revision: D60010017

fbshipit-source-id: 1ca268bfa1ede9f0e21c3e1fb773025f70c12e73
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Jul 23, 2024
1 parent 09c7323 commit c137ce3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
22 changes: 10 additions & 12 deletions folly/container/F14Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class F14BasicMap {
* @methodset Modifiers
*/
FOLLY_ALWAYS_INLINE iterator erase(const_iterator pos) {
return eraseInto(pos, [](key_type&&, mapped_type&&) {});
return eraseInto(pos, variadic_noop);
}

/**
Expand All @@ -641,23 +641,21 @@ class F14BasicMap {
* that accepts const_iterator
*/
FOLLY_ALWAYS_INLINE iterator erase(iterator pos) {
return eraseInto(pos, [](key_type&&, mapped_type&&) {});
return eraseInto(pos, variadic_noop);
}

/// Remove a range of elements.
iterator erase(const_iterator first, const_iterator last) {
return eraseInto(first, last, [](key_type&&, mapped_type&&) {});
return eraseInto(first, last, variadic_noop);
}

/// Remove a specific key.
size_type erase(key_type const& key) {
return eraseInto(key, [](key_type&&, mapped_type&&) {});
}
size_type erase(key_type const& key) { return eraseInto(key, variadic_noop); }

/// Remove a key, using a heterogeneous representation.
template <typename K>
EnableHeterogeneousErase<K, size_type> erase(K const& key) {
return eraseInto(key, [](key_type&&, mapped_type&&) {});
return eraseInto(key, variadic_noop);
}

protected:
Expand Down Expand Up @@ -1537,29 +1535,29 @@ class F14VectorMapImpl : public F14BasicMap<MapPolicyWithDefaults<
* @methodset Modifiers
*/
FOLLY_ALWAYS_INLINE iterator erase(const_iterator pos) {
return eraseInto(pos, [](key_type&&, mapped_type&&) {});
return eraseInto(pos, variadic_noop);
}

// This form avoids ambiguity when key_type has a templated constructor
// that accepts const_iterator
FOLLY_ALWAYS_INLINE iterator erase(iterator pos) {
return eraseInto(pos, [](key_type&&, mapped_type&&) {});
return eraseInto(pos, variadic_noop);
}

/// Remove a range of elements.
iterator erase(const_iterator first, const_iterator last) {
return eraseInto(first, last, [](key_type&&, mapped_type&&) {});
return eraseInto(first, last, variadic_noop);
}

/// Remove a specific key.
std::size_t erase(key_type const& key) {
return eraseInto(key, [](key_type&&, mapped_type&&) {});
return eraseInto(key, variadic_noop);
}

/// Remove a key, using a heterogeneous representation.
template <typename K>
EnableHeterogeneousVectorErase<K, std::size_t> erase(K const& key) {
return eraseInto(key, [](key_type&&, mapped_type&&) {});
return eraseInto(key, variadic_noop);
}

/**
Expand Down
18 changes: 8 additions & 10 deletions folly/container/F14Set.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,23 +403,21 @@ class F14BasicSet {
* @methodset Modifiers
*/
FOLLY_ALWAYS_INLINE iterator erase(const_iterator pos) {
return eraseInto(pos, [](value_type&&) {});
return eraseInto(pos, variadic_noop);
}

/// Remove a range of elements.
iterator erase(const_iterator first, const_iterator last) {
return eraseInto(first, last, [](value_type&&) {});
return eraseInto(first, last, variadic_noop);
}

/// Remove a specific key.
size_type erase(key_type const& key) {
return eraseInto(key, [](value_type&&) {});
}
size_type erase(key_type const& key) { return eraseInto(key, variadic_noop); }

/// Remove a key, using a heterogeneous representation.
template <typename K>
EnableHeterogeneousErase<K, size_type> erase(K const& key) {
return eraseInto(key, [](value_type&&) {});
return eraseInto(key, variadic_noop);
}

/**
Expand Down Expand Up @@ -1170,20 +1168,20 @@ class F14VectorSetImpl : public F14BasicSet<SetPolicyWithDefaults<

public:
FOLLY_ALWAYS_INLINE iterator erase(const_iterator pos) {
return eraseInto(pos, [](value_type&&) {});
return eraseInto(pos, variadic_noop);
}

iterator erase(const_iterator first, const_iterator last) {
return eraseInto(first, last, [](value_type&&) {});
return eraseInto(first, last, variadic_noop);
}

std::size_t erase(key_type const& key) {
return eraseInto(key, [](value_type&&) {});
return eraseInto(key, variadic_noop);
}

template <typename K>
EnableHeterogeneousVectorErase<K, std::size_t> erase(K const& key) {
return eraseInto(key, [](value_type&&) {});
return eraseInto(key, variadic_noop);
}

template <typename BeforeDestroy>
Expand Down
8 changes: 4 additions & 4 deletions folly/futures/Future-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ SemiFuture<T> SemiFuture<T>::deferEnsure(F&& func) && {

template <class T>
SemiFuture<Unit> SemiFuture<T>::unit() && {
return std::move(*this).deferValue([](T&&) {});
return std::move(*this).deferValue(variadic_noop);
}

template <typename T>
Expand Down Expand Up @@ -1273,7 +1273,7 @@ Future<T>::thenErrorImpl(

template <class T>
Future<Unit> Future<T>::then() && {
return std::move(*this).thenValue([](T&&) {});
return std::move(*this).thenValue(variadic_noop);
}

template <class T>
Expand Down Expand Up @@ -2185,8 +2185,8 @@ SemiFuture<T> SemiFuture<T>::within(
nestedExecutors.emplace_back(ctx->thisFuture.stealDeferredExecutor());
nestedExecutors.emplace_back(ctx->afterFuture.stealDeferredExecutor());
// Set trivial callbacks to treat the futures as consumed
ctx->thisFuture.setCallback_([](Executor::KeepAlive<>&&, Try<Unit>&&) {});
ctx->afterFuture.setCallback_([](Executor::KeepAlive<>&&, Try<Unit>&&) {});
ctx->thisFuture.setCallback_(variadic_noop);
ctx->afterFuture.setCallback_(variadic_noop);
futures::detail::getDeferredExecutor(fut)->setNestedExecutors(
std::move(nestedExecutors));
return fut;
Expand Down

0 comments on commit c137ce3

Please sign in to comment.