Skip to content

Change MaskPattern.Patterns to a list - #531

Merged
codebude merged 4 commits into
masterfrom
maskpattern_list
May 22, 2024
Merged

Change MaskPattern.Patterns to a list#531
codebude merged 4 commits into
masterfrom
maskpattern_list

Conversation

@Shane32

@Shane32 Shane32 commented May 19, 2024

Copy link
Copy Markdown
Owner

This code changes MaskPattern.Patterns to a list instead of a dictionary to hopefully make some code easier to understand.

Existing code

The index is stored zero-based within the QR code, and I was confused by this code here:

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L130

followed by

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L163

and

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L175-L176

which is actually correct because of

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L185

So since the dictionary is unnecessary, I converted it to a list. It should be faster too but I didn't check.

New code

Now we start with this:

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L118-L120

and uses are simple:

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L132

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L165

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L187

@Shane32

Shane32 commented May 22, 2024

Copy link
Copy Markdown
Owner Author

I'll need to fix conflicts here

Comment thread QRCoder/QRCodeGenerator.ModulePlacer.cs Outdated
Comment thread QRCoder/QRCodeGenerator.ModulePlacer.cs Outdated
@codebude

Copy link
Copy Markdown
Collaborator

Can you also have a look on the merge conflicts?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Refactoring of code without changes to functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants