refactor: eliminate code duplication and simplify core patterns#147
Open
refactor: eliminate code duplication and simplify core patterns#147
Conversation
- Remove 4 identical copies of fatal() — all files now import the pub fn from sqlite.zig - Collapse 19-case error switch in main() from ~100 lines to 22 using fatal() directly (it is noreturn) - Replace if-chain parse() in InputFormat/OutputFormat with std.meta.stringToEnum — stays in sync with enum variants automatically - Use beginTransaction/commitTransaction helpers in loader.zig instead of duplicating the inline sqlite3_exec logic - Replace byte-by-byte takeByte() JSON reading in columns.zig and validate.zig with allocRemaining(.unlimited) - Remove redundant @as(usize, N) casts in csv.zig unit tests No behaviour change. All tests pass, ziglint clean.
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
fatal()deduplicated: the 4 identical copies inmain.zig,modes/columns.zig,modes/validate.zig, andmodes/sample.zigremoved — all now import thepub fnfromsqlite.zig.main()collapsed: from ~100 lines with 19writeAll → flush → exitblocks down to 22 lines usingfatal()directly (it isnoreturn).parse()simplified informat.zig: chains ofif (mem.eql(...))replaced bystd.meta.stringToEnum— automatically stays in sync with the enum.loader.zig: inlinesqlite3_exec("BEGIN"/"COMMIT")replaced by thebeginTransaction/commitTransactionhelpers fromsqlite.zig.while (takeByte())loop incolumns.zigandvalidate.zigreplaced byallocRemaining(.unlimited).@as(usize, N)casts removed incsv.zig.Impact
No behaviour change. Pure refactoring.
Checklist
zig build test— all tests passziglint src build.zig— clean