-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use BumpPointer::default() #993
Conversation
Hopefully this captures what we discussed on Friday. Feel free to update the PR if I missed anything. @wks |
// Copy the bump pointer struct | ||
default_allocator.bump_pointer | ||
}; | ||
// Create a fastpath BumpPointer with default(). The BumpPointer from default() will guarantee to fail on the first allocation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we let the binding create BumpPointer
with default()
, we should document the behaviour of the default()
method, noting that we initialise it with 0 and 0 and it will be guaranteed to fail in fast path.
Currently there is a comment inside the BumpPointer::default()
method.
fn default() -> Self {
// Defaults to 0,0. In this case, the first
// allocation would naturally fail the check
// `cursor + size < limit`, and go to the slowpath.
BumpPointer {
cursor: Address::ZERO,
limit: Address::ZERO,
}
}
I think we can move the comment into the doc comment (///
) of the default()
method so that the user knows how the default()
method is intended to be used.
It is even better to mention this behaviour in the type-level doc comment of the BumpPointer
type, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made changes as suggested.
BumpPointer about the default values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR changes the code snippet in our doc to use
BumpPointer::default()
to create a new zero-initialized bump pointer struct. It also changes our internal implementation to useBumpPointer::default()
instead ofBumpPointer::new(zero, zero)
.