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

Tweak ThreadLocal fast-path functions

Summary: [Folly] Tweak `ThreadLocal` fast-path functions. Mostly code golf.

Differential Revision: D9732836

fbshipit-source-id: fc48a7c067c6961413e6aa94106ae26f87d3d603
parent 1d58fd57
...@@ -67,13 +67,8 @@ class ThreadLocal { ...@@ -67,13 +67,8 @@ class ThreadLocal {
: constructor_(std::forward<F>(constructor)) {} : constructor_(std::forward<F>(constructor)) {}
T* get() const { T* get() const {
T* const ptr = tlp_.get(); auto const ptr = tlp_.get();
if (LIKELY(ptr != nullptr)) { return FOLLY_LIKELY(!!ptr) ? ptr : makeTlp();
return ptr;
}
// separated new item creation out to speed up the fast path.
return makeTlp();
} }
T* operator->() const { T* operator->() const {
......
...@@ -434,20 +434,19 @@ struct StaticMeta final : StaticMetaBase { ...@@ -434,20 +434,19 @@ struct StaticMeta final : StaticMetaBase {
} }
FOLLY_ALWAYS_INLINE static ElementWrapper& get(EntryID* ent) { FOLLY_ALWAYS_INLINE static ElementWrapper& get(EntryID* ent) {
// Eliminate as many branches and as much extra code as possible in the
// cached fast path, leaving only one branch here and one indirection below.
uint32_t id = ent->getOrInvalid(); uint32_t id = ent->getOrInvalid();
#ifdef FOLLY_TLD_USE_FOLLY_TLS #ifdef FOLLY_TLD_USE_FOLLY_TLS
static FOLLY_TLS ThreadEntry* threadEntry{}; static FOLLY_TLS ThreadEntry* threadEntry{};
static FOLLY_TLS size_t capacity{}; static FOLLY_TLS size_t capacity{};
// Eliminate as many branches and as much extra code as possible in the
// cached fast path, leaving only one branch here and one indirection below.
if (UNLIKELY(capacity <= id)) {
getSlowReserveAndCache(ent, id, threadEntry, capacity);
}
#else #else
ThreadEntry* threadEntry{}; ThreadEntry* threadEntry{};
size_t capacity{}; size_t capacity{};
getSlowReserveAndCache(ent, id, threadEntry, capacity);
#endif #endif
if (FOLLY_UNLIKELY(capacity <= id)) {
getSlowReserveAndCache(ent, id, threadEntry, capacity);
}
return threadEntry->elements[id]; return threadEntry->elements[id];
} }
......
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