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.
raito force-pushed qm3ster/patch-1 from 5429e7b36b to 52fb329d1f 2025-08-03 16:28:44 +00:00 Compare
raito force-pushed qm3ster/patch-1 from 52fb329d1f to 30c949c07c 2025-08-03 16:30:39 +00:00 Compare
Some checks failed
Run CI on everything / pre-push (push) Failing after 13m27s
Run CI on everything / pre-push (pull_request) Successful in 20m36s
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.