Skip to content

Conversation

@braddunbar
Copy link
Contributor

A fundamental invariant of reserve is that it can extend capacity while the stored data remains the same, even if it's moved to a new allocation. As a result, len can never change during a call to reserve.

A fundamental invariant of `reserve` is that it can extend capacity
while the stored data remains the same, even if it's moved to a new
allocation. As a result, `len` can never change during a call to
`reserve`.
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Sorry for the delay.


// Update the info
self.ptr = vptr(v.as_mut_ptr().add(off));
self.len = v.len() - off;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about asserting that they are equal?

debug_assert_eq!(self.len, v.len() - off);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me! Added in f92c9f6.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks.

@Darksonn Darksonn merged commit e4af486 into tokio-rs:master Apr 9, 2024
@braddunbar braddunbar deleted the dont-set-len-in-reserve branch April 9, 2024 14:03
@mox692 mox692 mentioned this pull request Jul 30, 2024
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