refactor: remove useless magic in struct#730
Conversation
Its-Just-Nans
commented
Mar 18, 2026
- tiny struct
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant refactoring of how fixed-size blocks, particularly those with magic signatures, are handled within the codebase. The primary goal is to decouple the magic bytes from the core data structures, improving modularity and clarity. This change impacts how data blocks are parsed from and written to streams, and ensures that offset calculations correctly reflect the new structure. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
This PR refactors the ZIP specification handling by separating magic numbers from data blocks in a BlockWithMagic wrapper structure. The changes are well-structured and improve code organization by making magic numbers explicit in the serialization/deserialization process.
One critical issue found that must be fixed before merging: a debug print statement (eprintln!) was left in production code in src/spec.rs at line 264.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
There was a problem hiding this comment.
Code Review
This pull request is a nice refactoring that removes the explicit magic field from several structs and centralizes the magic number handling within the FixedSizeBlock trait by introducing a BlockWithMagic wrapper. This simplifies the struct definitions and makes the code cleaner. The changes are consistent across the codebase. I've found one minor issue with a leftover debug print statement that should be removed.
src/spec.rs
Outdated
| let BlockWithMagic { inner, .. } = block; | ||
| eprintln!("{} {}", block.as_bytes().len(), inner.as_bytes().len()); |
|
I don't really see any worst perf. Benching is hard, and I easily get good result and worst On this branch On the master branch Seems to be silghty faster on single read entry but still the same, always different results On this branch On master So this MR is more for code refactoring purpose |