Skip to content

feat(joystick/vector): Update to return const ref where possible#416

Merged
finger563 merged 4 commits intomainfrom
feat/const-refs
Apr 9, 2025
Merged

feat(joystick/vector): Update to return const ref where possible#416
finger563 merged 4 commits intomainfrom
feat/const-refs

Conversation

@finger563
Copy link
Copy Markdown
Contributor

Description

  • Update espp::Vector2d and espp::Joystick to return const references where possible

Motivation and Context

Reduces the amount of unnecessary copies in application code

How has this been tested?

Build and run math/example and joystick/example

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

* 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`
@finger563 finger563 self-assigned this Apr 9, 2025
@finger563 finger563 requested a review from Copilot April 9, 2025 18:57
@finger563 finger563 added enhancement New feature or request math joystick labels Apr 9, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

finger563 and others added 2 commits April 9, 2025 13:59
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2025

✅Static analysis result - no issues found! ✅

@finger563 finger563 merged commit 6d0d0f6 into main Apr 9, 2025
76 of 77 checks passed
@finger563 finger563 deleted the feat/const-refs branch April 9, 2025 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request joystick math

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants