Summary:
A smaller function makes it more likely it will be inlined
(it wasn't before, is now).
Test Plan: n/a
Reviewed By: tudorb@fb.com
FB internal diff:
D759996
T* get() const {
T* ptr = tlp_.get();
- if (UNLIKELY(ptr == nullptr)) {
- ptr = new T();
- tlp_.reset(ptr);
+ if (LIKELY(ptr != nullptr)) {
+ return ptr;
}
- return ptr;
+
+ // separated new item creation out to speed up the fast path.
+ return makeTlp();
}
T* operator->() const {
ThreadLocal(const ThreadLocal&) = delete;
ThreadLocal& operator=(const ThreadLocal&) = delete;
+ T* makeTlp() const {
+ T* ptr = new T();
+ tlp_.reset(ptr);
+ return ptr;
+ }
+
mutable ThreadLocalPtr<T,Tag> tlp_;
};