feat(joystick/vector): Update to return const ref where possible#416
Merged
feat(joystick/vector): Update to return const ref where possible#416
const ref where possible#416Conversation
* Update `espp::Vector2d` and `espp::Joystick` to return const references where possible Reduces the amount of unnecessary copies in application code Build and run `math/example` and `joystick/example`
Contributor
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
components/math/include/vector2d.hpp:79
- [nitpick] Returning a const reference for x() is effective for large types, but if T is a primitive or small type this change may not be optimal; consider adding documentation or a conditional specialization to clarify the design intent.
const T &x() const { return x_; }
components/joystick/src/joystick.cpp:77
- [nitpick] Ensure that returning a const reference for position() does not lead to unexpected lifetime issues for client code, particularly if the internal state may change.
const espp::Vector2f &espp::Joystick::position() const { return position_; }
components/joystick/src/joystick.cpp:79
- [nitpick] Verify that clients using raw() do not unintentionally rely on a copy of the data, as the returned reference is directly tied to the object’s internal state.
const espp::Vector2f &espp::Joystick::raw() const { return raw_; }
components/joystick/include/joystick.hpp:216
- [nitpick] Similarly, document the lifetime assumptions for the raw() getter to ensure that downstream clients understand that the returned reference is valid only as long as the underlying object remains unchanged.
const espp::Vector2f &raw() const;
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
✅Static analysis result - no issues found! ✅ |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
espp::Vector2dandespp::Joystickto return const references where possibleMotivation and Context
Reduces the amount of unnecessary copies in application code
How has this been tested?
Build and run
math/exampleandjoystick/exampleScreenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.