Skip to content

Optimize QRCodeData.SaveRawData and QRCodeData.GetRawData - #708

Open
KrisVandermotten wants to merge 2 commits into
Shane32:masterfrom
KrisVandermotten:SaveRawData
Open

KrisVandermotten wants to merge 2 commits into
Shane32:masterfrom
KrisVandermotten:SaveRawData

Conversation

@KrisVandermotten

@KrisVandermotten KrisVandermotten commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Optimize QRCodeData.SaveRawData and QRCodeData.GetRawData by

  • eliminating the Queue<int> to store the modules;
  • writing directly to a FileStream instead of using an intermediate MemoryStream.

Test plan

Tests existed to test GetRawData. Tests were added to test SaveRawData.

The corresponding constructors were not modified to ensure the updated methods remain compatible with those existing constructors. This ensures the updated methods still produce the same output as before.

The test helper ToBitString was trivially optimized a bit. It doesn't hurt if tests are somewhat efficiënt.

Closing issues

Fixes #705

Summary by CodeRabbit

  • New Features
    • QR code data can now be saved directly to a file, with options for uncompressed, Deflate, or GZip formats.
  • Improvements
    • Saved QR code data can be loaded with its matrix size and contents preserved.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 96b48c85-33c1-4cce-bd0d-37551e80d466
📥 Commits

Reviewing files that changed from the base of the PR and between 197802e and 80d43e6.

📒 Files selected for processing: 1
  • QRCoder/QRCodeData.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📝 Walkthrough

QR code data serialization now writes through streams. SaveRawData writes directly to a file stream, and tests cover saved-data round trips with uncompressed, Deflate, and GZip modes.

Changes: QR code data serialization

Layer / File(s) Summary
Stream-based serialization and file output
QRCoder/QRCodeData.cs
GetRawData delegates serialization to a stream-based writer. SaveRawData writes to a file stream. The writer retains the QRR header and row-major bit encoding, packs bits incrementally, and adds a debug assertion for remaining padding bits when reading.
File round-trip validation
QRCoderTests/QRGeneratorTests.cs
A new test checks saved and reloaded data in uncompressed, Deflate, and GZip modes. ToBitString now fills a character array in bit order.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: codebude, shane32

Merge Risk: ⚪ Minimal · up to 80d43

The supplied change context indicates that stream-based serialization retains the existing format and that file round trips cover the supported compression modes. No actionable merge-blocking risk is identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the optimization of QRCodeData.SaveRawData and QRCodeData.GetRawData, which is the main change.
Linked Issues check Passed Issue #705 requires SaveRawData to avoid the byte-array allocation. SaveRawData now opens a FileStream and calls the private stream-based WriteRawData method. WriteRawData packs modules and writes the…
Out of Scope Changes check Passed The changes stay within issue #705. The constructor assertion checks the serialized padding invariant. The file round-trip tests verify SaveRawData. The ToBitString change optimizes a helper used by t…
Full details: Linked Issues check

Explanation

Issue #705 requires SaveRawData to avoid the byte-array allocation. SaveRawData now opens a FileStream and calls the private stream-based WriteRawData method. WriteRawData packs modules and writes them directly to the target stream, including Deflate and GZip handling. Tests cover file save and reload for all compression modes.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #705. The constructor assertion checks the serialized padding invariant. The file round-trip tests verify SaveRawData. The ToBitString change optimizes a helper used by those tests. No unrelated production behavior is demonstrated.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Remove byte[] allocation in QRCodeData.SaveRawData

1 participant