Skip to content

uefi: Clear the Vec in DevicePathBuilder::with_vec #794

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

Merged
merged 1 commit into from
May 8, 2023

Conversation

nicholasbishop
Copy link
Member

Previously there was an implicit assumption that the Vec was empty; clear it to ensure this.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

Previously there was an implicit assumption that the `Vec` was empty; clear it
to ensure this.
@@ -83,8 +83,11 @@ impl<'a> DevicePathBuilder<'a> {
}

/// Create a builder backed by a `Vec`.
///
/// The `Vec` is cleared before use.
#[cfg(feature = "alloc")]
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't the method create the vector itself now?

Copy link
Member Author

Choose a reason for hiding this comment

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

For performance. clear doesn't free any memory, it just resets the initialized length. So you could use Vec::with_capacity to preallocate before building the device path.

@phip1611 phip1611 merged commit 98670a3 into rust-osdev:main May 8, 2023
@nicholasbishop nicholasbishop deleted the bishop-fix-vec-with branch May 8, 2023 20:41
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