Commit a3d36214 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Use tag_t instead of TypeTuple for singletons

Summary: [Folly] Use `tag_t` instead of `TypeTuple` for singletons.

Reviewed By: andriigrynenko

Differential Revision: D14927424

fbshipit-source-id: fdd33a30d5abde67c50df009a0cacc89462278b7
parent 22b69cc8
...@@ -43,13 +43,13 @@ class SingletonThreadLocalBase { ...@@ -43,13 +43,13 @@ class SingletonThreadLocalBase {
}; };
template <typename T, typename Tag, typename Make, typename TLTag> template <typename T, typename Tag, typename Make, typename TLTag>
explicit UniqueBase(TypeTuple<T, Tag, Make, TLTag>) noexcept explicit UniqueBase(tag_t<T, Tag, Make, TLTag>) noexcept
: UniqueBase( : UniqueBase(
typeid(T), typeid(T),
typeid(Tag), typeid(Tag),
typeid(Make), typeid(Make),
typeid(TLTag), typeid(TLTag),
detail::createGlobal<Value, TypeTuple<T, Tag, UniqueBase>>()) {} detail::createGlobal<Value, tag_t<T, Tag, UniqueBase>>()) {}
UniqueBase(Ref type, Ref tag, Ref make, Ref tltag, Value& value) noexcept; UniqueBase(Ref type, Ref tag, Ref make, Ref tltag, Value& value) noexcept;
}; };
...@@ -98,7 +98,7 @@ template < ...@@ -98,7 +98,7 @@ template <
class SingletonThreadLocal : private detail::SingletonThreadLocalBase { class SingletonThreadLocal : private detail::SingletonThreadLocalBase {
private: private:
struct Unique final : UniqueBase { struct Unique final : UniqueBase {
Unique() noexcept : UniqueBase(detail::TypeTuple<T, Tag, Make, TLTag>{}) {} Unique() noexcept : UniqueBase(tag_t<T, Tag, Make, TLTag>{}) {}
}; };
static Unique unique; static Unique unique;
......
...@@ -45,8 +45,5 @@ struct DefaultMake { ...@@ -45,8 +45,5 @@ struct DefaultMake {
} }
}; };
template <typename...>
struct TypeTuple {};
} // namespace detail } // namespace detail
} // namespace folly } // namespace folly
...@@ -59,7 +59,7 @@ class StaticSingletonManagerWithRtti { ...@@ -59,7 +59,7 @@ class StaticSingletonManagerWithRtti {
FOLLY_EXPORT FOLLY_ALWAYS_INLINE static T& create() { FOLLY_EXPORT FOLLY_ALWAYS_INLINE static T& create() {
// gcc and clang behave poorly if typeid is hidden behind a non-constexpr // gcc and clang behave poorly if typeid is hidden behind a non-constexpr
// function, but typeid is not constexpr under msvc // function, but typeid is not constexpr under msvc
static Arg arg{{nullptr}, FOLLY_TYPE_INFO_OF(TypeTuple<T, Tag>), make<T>}; static Arg arg{{nullptr}, FOLLY_TYPE_INFO_OF(tag_t<T, Tag>), make<T>};
auto const v = arg.cache.load(std::memory_order_acquire); auto const v = arg.cache.load(std::memory_order_acquire);
auto const p = FOLLY_LIKELY(!!v) ? v : create_<noexcept(T())>(arg); auto const p = FOLLY_LIKELY(!!v) ? v : create_<noexcept(T())>(arg);
return *static_cast<T*>(p); return *static_cast<T*>(p);
......
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