FastLED 3.10.9
Loading...
Searching...
No Matches

◆ rehash_internal()

template<typename Key, typename T, typename Hash = Hash<Key>, typename KeyEqual = EqualTo<Key>, int INLINED_COUNT = FASTLED_HASHMAP_INLINED_COUNT>
void fl::unordered_map< Key, T, Hash, KeyEqual, INLINED_COUNT >::rehash_internal ( fl::size new_cap)
inlineprivate

Definition at line 916 of file unordered_map.h.

916 {
918#if FL_PLATFORM_HAS_LARGE_MEMORY
919 // Large stacks: keep the scratch local and skip a heap round trip.
922#else
923 // Small stacks: the old buckets (an inline Entry buffer) and the
924 // 1024-bit occupancy copy cost about 1 KB on the stack, which
925 // overflowed ESP8266's 4 KB loop stack when an RPC registry grew
926 // during setup(), so they come from the map's memory resource.
927 struct Scratch {
931 };
932 fl::memory_resource* resource = _buckets.get_resource();
933 if (resource == nullptr) {
935 }
936 void* mem = resource->allocate(sizeof(Scratch));
937 if (mem == nullptr) {
938 // Out of memory: stay at the current size. The table is at most
939 // 70% full, so inserts still find a slot and retry the grow.
940 return;
941 }
946#endif
947
948 _buckets.swap(old);
949 _buckets.clear();
950 _buckets.assign(new_cap, Entry{});
951
952 _occupied.reset();
953 _occupied.resize(new_cap);
954 _deleted.reset();
955 _deleted.resize(new_cap);
956
957 _size = _tombstones = 0;
958
959 for (fl::size i = 0; i < old.size(); i++) {
960 if (old_occupied.test(i))
962 }
963#if !FL_PLATFORM_HAS_LARGE_MEMORY
964 scratch->~Scratch();
965 resource->deallocate(mem, sizeof(Scratch));
966#endif
967 }
fl::bitset< 1024 > _occupied
fl::size size() const FL_NO_EXCEPT
fl::vector_inlined< Entry, INLINED_COUNT > _buckets
pair< iterator, bool > insert(const Key &key, const T &value) FL_NO_EXCEPT
fl::bitset< 1024 > _deleted
static fl::size next_power_of_two(fl::size n) FL_NO_EXCEPT
memory_resource * default_memory_resource() FL_NO_EXCEPT
Get the default memory resource (wraps fl::Malloc / fl::Free / fl::realloc).