Commit 6ed9d378 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

shrink UniqueInstance ctor

Summary:
It is monomorphized but called rarely. Best to optimize for size.

The `UniqueInstance` ctor is currently called in the constructor of each translation unit for each distinct instance of `SingletonThreadLocal`.

`UniqueInstance` may be extended to more use-cases so it is worthwhile optimizing for size.

Reviewed By: luciang

Differential Revision: D27602938

fbshipit-source-id: e4077830544516219485814ccc48805b7bb38e34
parent ebe2f775
......@@ -83,13 +83,9 @@ std::string render(Value value) {
} // namespace
void UniqueInstance::enforce(
Ptr tmpl,
Ptr const* ptrs,
std::uint32_t key_size,
std::uint32_t mapped_size,
Value& global) noexcept {
Value const local{tmpl, ptrs, key_size, mapped_size};
void UniqueInstance::enforce(Arg& arg) noexcept {
auto const& local = arg.local;
auto& global = StaticSingletonManager::create<Value>(arg.global);
if (!global.tmpl) {
global = local;
......
......@@ -19,6 +19,7 @@
#include <cstdint>
#include <typeinfo>
#include <folly/CppAttributes.h>
#include <folly/detail/StaticSingletonManager.h>
namespace folly {
......@@ -30,12 +31,14 @@ class UniqueInstance {
explicit UniqueInstance(...) noexcept {}
#else
template <template <typename...> class Z, typename... Key, typename... Mapped>
FOLLY_EXPORT explicit UniqueInstance(
FOLLY_EXPORT FOLLY_ALWAYS_INLINE explicit UniqueInstance(
tag_t<Z<Key..., Mapped...>>, tag_t<Key...>, tag_t<Mapped...>) noexcept {
Ptr const tmpl = &typeid(key_t<Z>);
static Ptr const tmpl = &typeid(key_t<Z>);
static Ptr const ptrs[] = {&typeid(Key)..., &typeid(Mapped)...};
auto& global = createGlobal<Value, key_t<Z, Key...>>();
enforce(tmpl, ptrs, sizeof...(Key), sizeof...(Mapped), global);
static Arg arg{
{tmpl, ptrs, sizeof...(Key), sizeof...(Mapped)},
{tag<Value, key_t<Z, Key...>>}};
enforce(arg);
}
#endif
......@@ -59,15 +62,12 @@ class UniqueInstance {
std::uint32_t key_size;
std::uint32_t mapped_size;
};
struct Arg {
Value local;
StaticSingletonManager::ArgCreate<true> global;
};
// Under Clang, this call signature shrinks the aligned and padded size of
// call-sites, as compared to a call signature taking Value or Value const&.
static void enforce(
Ptr tmpl,
Ptr const* ptrs,
std::uint32_t key_size,
std::uint32_t mapped_size,
Value& global) noexcept;
static void enforce(Arg& arg) noexcept;
};
} // namespace detail
......
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