Repository navigation
Avoid temporary color arrays in PDF and bitmap renderers - #713
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Hex color parsing QRCoder/Extensions/StringExtensions.cs |
Span-enabled builds parse hex colors into a supplied buffer and validate the input byte count. Other builds retain the allocating parser. |
Bitmap renderer integration QRCoder/BitmapByteQRCode.cs, QRCoderTests/BitmapByteQRCodeRendererTests.cs |
The bitmap renderer routes color overloads through a shared core method. Span-enabled builds parse colors into stack-allocated buffers. Tests compare equivalent colors, verify default colors, and check invalid input. |
PDF renderer integration QRCoder/PdfByteQRCode.cs, QRCoderTests/PdfByteQRCodeRendererTests.cs |
Span-enabled builds parse PDF colors into stack-allocated buffers. Other builds retain array-based parsing and length validation. Tests cover equivalent colors, incorrect lengths, and invalid digits. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Possibly related PRs
- Shane32/QRCoder#712: Updates
PdfByteQRCode.GetGraphicallocation behavior and RGB color validation, which overlap with the PDF renderer changes here.
Suggested reviewers: krisvandermotten, gfoidl
Merge Risk: 
Minimal · up to 6e4e3
-
No actionable merge-blocking risk was established for this change.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 5 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- 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.
| Span<byte> darkColor = stackalloc byte[3]; | ||
| Span<byte> lightColor = stackalloc byte[3]; |
There was a problem hiding this comment.
| Span<byte> darkColor = stackalloc byte[3]; | |
| Span<byte> lightColor = stackalloc byte[3]; | |
| Span<byte> scratch = stackalloc byte[8]; | |
| Span<byte> darkColor = sratch.Slice(0, 3); | |
| Span<byte> lightColor = scratch.Slice(3, 3); |
| Span<byte> darkColor = stackalloc byte[3]; | ||
| Span<byte> lightColor = stackalloc byte[3]; |
| var offset = colorString.StartsWith('#') ? 1 : 0; | ||
| var byteCount = (colorString.Length - offset) / 2; |
There was a problem hiding this comment.
var and typed variables are used quite inconsistent in the code.
Can we use the strong typed declaration? It's easier to read w/o IDE then.
There was a problem hiding this comment.
I can do a follow-up PR to clean this up across the codebase
Summary
PDF and bitmap rendering allocate temporary byte arrays when parsing hex colors. Parse directly into stack-allocated RGB buffers on
HAS_SPANtargets, and use a private span-based bitmap rendering core so default black-and-white rendering also avoids these color arrays.Compile
HexColorToByteArrayonly under!HAS_SPAN. Preserve bitmap parsing and validation of extra color bytes, PDF's exact RGB length requirement, and the existing public API.Test plan
dotnet build QRCoder/QRCoder.csproj --no-restore.net462,netcoreapp2.1,netcoreapp3.1,net5.0-windows, andnet6.0-windows(185 passing cases).git diff --checkpassed.Summary by CodeRabbit
#prefixes.