-
Notifications
You must be signed in to change notification settings - Fork 2
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
Enhance DXL item initialization by prioritizing 'Limit' parameters. #5
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
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 current implementation separates the processing of "Limit" items and other items into two loops. While this approach works, it can be optimized by combining the loops into one. By doing so, we reduce the number of iterations over gpio.parameters, making the code simpler and slightly more efficient. Additionally, separating the conditions for "Limit" items and others within the loop maintains the existing logic while improving readability and maintainability.
Here’s a suggested implementation:
Key Benefits:
Efficiency: The parameters are iterated only once.
Maintainability: Combining the loops reduces redundancy, and separating conditions ("Limit" vs. others) within the loop improves clarity.
Logic Preservation: The "Limit" items are still processed before others, maintaining the intended behavior.
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.
Thank you for your suggestion to combine the limit parameters and other parameters into a single loop. However, the original code explicitly ensures that all limit parameters are written before any other parameters. This two-phase approach is critical because it guarantees that subsequent parameter writes will fall within valid, pre-established limits.
When we merge everything into a single loop, we lose that strict ordering. Although the if (it.first.find("Limit") ... ) check is present, we can’t guarantee all limit parameters will be handled first in a single pass—especially in containers where iteration order can be non-deterministic. That means some non-limit parameters might get set before the corresponding limit parameters, which could lead to invalid configurations.
I do appreciate the goal of reducing loops and simplifying the code, but preserving the limit-first logic is paramount for reliable initialization. If you have any other ideas on how to keep this guarantee while simplifying the loops, I am open to further discussion!
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.
Thank you for your detailed explanation and for pointing out the importance of preserving the strict ordering of limit parameters before other parameters. You are absolutely correct that combining everything into a single loop could break the intended logic by potentially allowing non-limit parameters to be set before their corresponding limits, especially in cases where the iteration order of the container is non-deterministic.
Additionally, I considered an alternative approach where the first loop processes and removes limit parameters from the container, reducing the number of iterations required in the second loop. However, as this would involve modifying the container during iteration, it might not yield significant efficiency improvements and could introduce unnecessary complexity.
Given these points, I agree that your proposed two-phase approach is the most reliable way to ensure the initialization process remains robust and predictable. Thank you again for the clarification, and I’m happy to proceed with your method. If any further ideas come to mind, I’ll be sure to share them! 😊