Don't allocate a Vec to pad with zeros. #473

Open
qm3ster wants to merge 2 commits from qm3ster/patch-1 into master
qm3ster commented 2025-07-30 16:40:20 +00:00 (Migrated from github.com)

Might be worth it not to use uefi::fs::FileSystem::read, because it:

  1. returns an exactly info.file_size() sized Vec, so it reallocates the whole file on any padding
  2. zeroes the memory first
  3. doesn't align start (not sure how to fix this without unsafe, not sure if it has benefits either)

Instead, one Vec<u8> (or unsafe buffer) could be preallocated for kernel+pad+initrd+(pad+initrdN)* by iterating the metadata first, which the above method does internally, and then RegularFile::read used.

Might be worth it not to use `uefi::fs::FileSystem::read`, because it: 1. returns an exactly `info.file_size()` sized `Vec`, so it reallocates the whole file on any padding 2. zeroes the memory first 3. doesn't align start (not sure how to fix this without unsafe, not sure if it has benefits either) Instead, one `Vec<u8>` (or unsafe buffer) could be preallocated for kernel+pad+initrd+(pad+initrdN)* by iterating the metadata first, which the above method does internally, and then `RegularFile::read` used.
RaitoBezarius (Migrated from github.com) approved these changes 2025-07-31 00:50:33 +00:00
RaitoBezarius (Migrated from github.com) left a comment

Sounds good to me.
Testing is needed before merge.

Sounds good to me. Testing is needed before merge.
blitz commented 2025-09-01 16:53:27 +00:00 (Migrated from github.com)

Looks good to me as well. @qm3ster Can you squash your changes into one commit with a commit message that matches the others? I'll give this a try on my system when I get a chance!

Looks good to me as well. @qm3ster Can you squash your changes into one commit with a commit message that matches the others? I'll give this a try on my system when I get a chance!
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin qm3ster/patch-1:qm3ster/patch-1
git switch qm3ster/patch-1

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff qm3ster/patch-1
git switch qm3ster/patch-1
git rebase master
git switch master
git merge --ff-only qm3ster/patch-1
git switch qm3ster/patch-1
git rebase master
git switch master
git merge --no-ff qm3ster/patch-1
git switch master
git merge --squash qm3ster/patch-1
git switch master
git merge --ff-only qm3ster/patch-1
git switch master
git merge qm3ster/patch-1
git push origin master
Sign in to join this conversation.
No description provided.