refactor: Deduplicate integrity label builders in Rust guard#2963
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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_LEVELSand a sharedbuild_integrity_labels()helper to generate hierarchical integrity labels. - Simplifies
none_integrity,reader_integrity,writer_integrity, andmerged_integrityto 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.
This was referenced Apr 1, 2026
This was referenced Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts a shared
build_integrity_labels()helper andINTEGRITY_LEVELSconstant to eliminate duplicatedformat_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_LEVELSconstant: Ordered array of (prefix, base) tuples for the four integrity levelsbuild_integrity_labels(): Private helper that builds hierarchical labels up to a given level usingINTEGRITY_LEVELSnone_integrity(level 0),reader_integrity(level 1),writer_integrity(level 2),merged_integrity(level 3) are now one-linersintegrity_rank(): IteratesINTEGRITY_LEVELSin reverse, returning on first match — avoids allocating unused label stringsImpact
helpers.rs(net -58 lines)Closes #2912