Skip to content

refactor: Deduplicate integrity label builders in Rust guard#2963

Merged
lpcox merged 1 commit intomainfrom
fix/rust-guard-integrity-dedup-2912
Mar 31, 2026
Merged

refactor: Deduplicate integrity label builders in Rust guard#2963
lpcox merged 1 commit intomainfrom
fix/rust-guard-integrity-dedup-2912

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Mar 31, 2026

Summary

Extracts a shared build_integrity_labels() helper and INTEGRITY_LEVELS constant to eliminate duplicated format_integrity_label() calls across four integrity builder functions (none_integrity, reader_integrity, writer_integrity, merged_integrity).

Also refactors integrity_rank() to use lazy label allocation — checking labels from highest to lowest rank, building only one label string at a time instead of eagerly allocating all four before checking any.

Changes

  • INTEGRITY_LEVELS constant: Ordered array of (prefix, base) tuples for the four integrity levels
  • build_integrity_labels(): Private helper that builds hierarchical labels up to a given level using INTEGRITY_LEVELS
  • Simplified public functions: none_integrity (level 0), reader_integrity (level 1), writer_integrity (level 2), merged_integrity (level 3) are now one-liners
  • Lazy integrity_rank(): Iterates INTEGRITY_LEVELS in reverse, returning on first match — avoids allocating unused label strings

Impact

  • -91 / +33 lines in helpers.rs (net -58 lines)
  • All 248 Rust tests pass
  • All Go unit + integration tests pass
  • No behavioral changes — pure refactor

Closes #2912

Extract build_integrity_labels() helper and INTEGRITY_LEVELS constant to
replace duplicated format_integrity_label() calls across none_integrity,
reader_integrity, writer_integrity, and merged_integrity functions.

Refactor integrity_rank() to use lazy allocation - checks labels from
highest to lowest rank, allocating only one label string at a time
instead of eagerly building all four before checking any.

Closes #2912

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 31, 2026 23:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors Rust guard integrity label generation to remove duplicated label-building logic and reduce unnecessary allocations when computing integrity rank, improving maintainability (and minor perf in hot paths) without changing behavior.

Changes:

  • Introduces INTEGRITY_LEVELS and a shared build_integrity_labels() helper to generate hierarchical integrity labels.
  • Simplifies none_integrity, reader_integrity, writer_integrity, and merged_integrity to one-liners using the shared helper.
  • Updates integrity_rank() to check integrity labels lazily from highest to lowest, allocating only as needed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

[rust-guard] Rust Guard: Deduplicate integrity label builders + lazy alloc in integrity_rank

2 participants