Skip to content

Conversation

symious
Copy link
Contributor

@symious symious commented Mar 20, 2025

The original code won't move the nextAvail.

Say we have 5 slots, and all allocated.
T1. nextAvail = 5, free = {}
T2. dealloc(2), nextAvail = 5, free = {2}
T3. dealloc(3), nextAvail = 5, free = {2, 3}
T4. dealloc(4)

  1. 4 == nextAvail - 1, so check while
  2. free.find(--nextAvail), which is free.find(4) is free.end(), so returned directly.

Or is it because of performance issue to remove the free.erase logic here? If so we don't need to while check here.

while (free.find(--nextAvail) != free.end()) {
// move back next avail as much as possible
;
nextAvail--;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer the prefix operator here when the result is not needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. But for a tiny style issue, I think the fix is good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echaozh Thank you for the review, updated the PR, PTAL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants