-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add qrio.QRDecoder.find() to locate codes without decoding #8467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple questions about your API design choices. Thanks for the PR!
shared-module/qrio/QRDecoder.c
Outdated
if (quirc_decode(&self->code, &self->data) != QUIRC_SUCCESS) { | ||
continue; | ||
mp_obj_t code_obj; | ||
if (decode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit weird to me. Almost always there is a 1:1 relationship between Python functions and their C common_hal parts. Could you refactor this so that find()
and decode()
share code but have two separate common_hal functions that each include their piece of this branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way I can think of doing this cleanly is to rename this function, and then have two one-liner common_hal functions that call it, with true or false. Would that be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a little better but not what I'm thinking. Ideally this code would be split apart. I bet you can factor out the start through quirc_end and return quirc_count(). You'll end up with a loop in each function that mirrors this one (but simpler without the if).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still have two functions identical except for what is inside that if, so I don't see much point? I will try to come up with something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved as much as I could without passing too many variables around to a common function, but there is still a lot of duplication. I'm not happy with it, but I can't see how to improve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was thinking. Thanks!
Cool, thanks! |
Fix #8452