Skip to content

Conversation

@stuqdog
Copy link
Member

@stuqdog stuqdog commented Feb 13, 2024

  • adds performance-unnecessary-value-param checks to clang-tidy
  • (flyby) implement a previously-unimplemented to_proto method
  • (flyby) change Vector3::to_proto to no longer be static

Comment on lines -48 to 54

viam::common::v1::Vector3 Vector3::to_proto(const Vector3& vec) {
viam::common::v1::Vector3 Vector3::to_proto() const {
viam::common::v1::Vector3 result;
result.set_x(vec.x());
result.set_y(vec.y());
result.set_z(vec.z());
result.set_x(x());
result.set_y(y());
result.set_z(z());
return result;
};
Copy link
Member Author

Choose a reason for hiding this comment

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

(flyby) this method was marked as static but just took an object ref as its only argument. I see no reason why this shouldn't just be a regular class method so I went ahead and made the change.

Comment on lines +75 to +82
viam::component::movementsensor::v1::GetPositionResponse MovementSensor::to_proto(
const position& position) {
component::movementsensor::v1::GetPositionResponse proto;
proto.set_altitude_m(position.altitude_m);
*proto.mutable_coordinate() = position.coordinate.to_proto();
return proto;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

(flyby) this was declared in the header but somehow never defined. That might mean it's better off to just delete it tbh, but it seemed more conservative to just add the implementation rq.

Comment on lines -3 to -14
#include <algorithm>
#include <chrono>
#include <cstddef>
#include <iostream>
#include <memory>
#include <mutex>
#include <ostream>
#include <set>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
Copy link
Member Author

Choose a reason for hiding this comment

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

(flyby) unused imports

@stuqdog stuqdog requested a review from acmorrow February 14, 2024 17:10
@stuqdog stuqdog marked this pull request as ready for review February 14, 2024 17:10
@stuqdog stuqdog requested a review from a team as a code owner February 14, 2024 17:10
@stuqdog stuqdog requested review from njooma and purplenicole730 and removed request for a team February 14, 2024 17:10
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

This LGTM. There are a few places where you opted to transform an existing value parameter into a const& but where the object looks like it is then copied from the &. In principle those could probably be moves. Basically:

If you start with:

void foo(Value v) {
    do_something(v);
}

You could either go to:

void foo(const Value& v) {  // No copy here
    do_something(v);            // Copy here
}

Or

void foo(Value v) {                         // Copy OR move here; depends on caller
    do_something(std::move(v));  // Move here
}

So the former solution is a guaranteed copy in the implementation. The latter solution is either a copy and a move or two moves, depending on whether the caller provides an lvalue or an rvalue.

Anyway, I'm not proposing you go through this review and adjust. I think what you have here is fine especially if you are doing it primarily to placate the linter.

}

void HandlerMap_::add_model(Model model, RPCSubtype subtype) {
void HandlerMap_::add_model(const Model& model, const RPCSubtype& subtype) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would still want this as a & if you std::move'd model below.

};

RobotClient::RobotClient(std::shared_ptr<ViamChannel> channel)
RobotClient::RobotClient(const std::shared_ptr<ViamChannel>& channel)
Copy link
Member

Choose a reason for hiding this comment

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

Could also leave it a value and std::move it on 220 probably.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh good catch, thanks! Fixed.


std::shared_ptr<RobotClient> RobotClient::with_channel(std::shared_ptr<ViamChannel> channel,
Options options) {
std::shared_ptr<RobotClient> RobotClient::with_channel(const std::shared_ptr<ViamChannel>& channel,
Copy link
Member

Choose a reason for hiding this comment

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

Ditto re maybe a std::move below makes if OK to pass by value?

@stuqdog stuqdog merged commit 9eedf7a into viamrobotics:main Feb 16, 2024
@stuqdog stuqdog deleted the performance-unnecessary-value-param branch February 16, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants