Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/react-native/React/Fabric/Utils/RCTIdentifierPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ class RCTIdentifierPool {

int dequeue()
{
while (true) {
for (size_t attempt = 0; attempt < size; attempt++) {
if (!usage[lastIndex]) {
usage[lastIndex] = true;
return lastIndex;
}
lastIndex = (lastIndex + 1) % size;
}

// Every identifier is taken, which only happens when identifiers were leaked.
// Reclaim them all instead of scanning forever: a reused identifier is a
// transient glitch, while an endless loop here hangs the main thread.
usage.reset();
usage[lastIndex] = true;
return lastIndex;
}

void reset()
Expand All @@ -39,7 +46,7 @@ class RCTIdentifierPool {

private:
std::bitset<size> usage;
int lastIndex;
int lastIndex{0};
};

} // namespace facebook::react
Loading