- // if id is invalid, it is equal to uint32_t's max value.
- // x <= max value is always true
+#ifdef FOLLY_TLD_USE_FOLLY_TLS
+ static FOLLY_TLS ThreadEntry* threadEntry{};
+ 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
+ ThreadEntry* threadEntry{};
+ size_t capacity{};
+ getSlowReserveAndCache(ent, id, threadEntry, capacity);
+#endif
+ return threadEntry->elements[id];
+ }
+
+ static void getSlowReserveAndCache(
+ EntryID* ent,
+ uint32_t& id,
+ ThreadEntry*& threadEntry,
+ size_t& capacity) {
+ auto& inst = instance();
+ threadEntry = inst.threadEntry_();