victory-loader: avoid the image copy with prepare_owned (PREPARE-OWNED-BUFFER) #3727

Open
cloph-dsp wants to merge 1 commit from upstream-pr/3727 into main
cloph-dsp commented 2026-11-28 12:06:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T12:06:44Z.


Depends on: #1633

What

prepare() copied the whole image (original.to_vec()) before patching it. Callers that already own the bytes — map_dll reads the file into a Vec — paid for a second executable-size allocation. Add prepare_owned(Vec<u8>) which takes the buffer by value, hashes the original bytes once, and patches in place. prepare(&[u8]) stays as a thin wrapper so borrowed callers are unaffected.

Change

  • crates/victory-loader/src/prepare.rs: add prepare_owned, keep prepare as a wrapper, synthetic test comparing borrowed vs owned preparation (bytes, info, hash, file name).
  • crates/victory-loader/src/lib.rs: re-export prepare_owned.
  • crates/victory-loader/src/windows.rs: map_dll passes its already-owned Vec directly.

Validation

Windows, Rust 1.100.0/MSVC, per-worktree CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, --locked:

  • cargo test --locked -p victory-loader --lib -- prepare::tests::owned_buffer_matches_borrowed_preparation --exact --test-threads=1 --quiet → 1 passed, 0 failed, 35 filtered, exit 0.
  • cargo test --locked -p victory-loader --lib -- prepare::tests --test-threads=1 --quiet → 5 passed, 0 failed, 31 filtered, exit 0.
  • git grep -F for the new test name on base 63bcca43c6a00a758510398fa43096ce7e4f7df0: no match (test is new); git diff --check clean (3 files, +25/-6).

GPU/driver: N/A (CPU-only byte manipulation; the Windows load path only changes which owned buffer is handed in). The tests use the local test binary as input — no game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5539950529 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3727). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T12:06:44Z. --- Depends on: #1633 ## What `prepare()` copied the whole image (`original.to_vec()`) before patching it. Callers that already own the bytes — `map_dll` reads the file into a `Vec` — paid for a second executable-size allocation. Add `prepare_owned(Vec<u8>)` which takes the buffer by value, hashes the original bytes once, and patches in place. `prepare(&[u8])` stays as a thin wrapper so borrowed callers are unaffected. ## Change - `crates/victory-loader/src/prepare.rs`: add `prepare_owned`, keep `prepare` as a wrapper, synthetic test comparing borrowed vs owned preparation (bytes, info, hash, file name). - `crates/victory-loader/src/lib.rs`: re-export `prepare_owned`. - `crates/victory-loader/src/windows.rs`: `map_dll` passes its already-owned `Vec` directly. ## Validation Windows, Rust 1.100.0/MSVC, per-worktree `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, `--locked`: - `cargo test --locked -p victory-loader --lib -- prepare::tests::owned_buffer_matches_borrowed_preparation --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 35 filtered, exit 0. - `cargo test --locked -p victory-loader --lib -- prepare::tests --test-threads=1 --quiet` → 5 passed, 0 failed, 31 filtered, exit 0. - `git grep -F` for the new test name on base `63bcca43c6a00a758510398fa43096ce7e4f7df0`: no match (test is new); `git diff --check` clean (3 files, +25/-6). GPU/driver: N/A (CPU-only byte manipulation; the Windows load path only changes which owned buffer is handed in). The tests use the local test binary as input — no game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3727:upstream-pr/3727'
git switch 'upstream-pr/3727'

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 'main'
git merge --no-ff 'upstream-pr/3727'
git switch 'upstream-pr/3727'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3727'
git switch 'upstream-pr/3727'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3727'
git switch 'main'
git merge --squash 'upstream-pr/3727'
git switch 'main'
git merge --ff-only 'upstream-pr/3727'
git switch 'main'
git merge 'upstream-pr/3727'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3727
No description provided.