Skip to content

Commit cc55663

Browse files
authoredJul 2, 2023
[tidy] fix move const performance (#354)
1 parent 55402e5 commit cc55663

6 files changed

+29
-80
lines changed
 

‎.clang-tidy

-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ Checks: '*,
2323
-hicpp-avoid-c-arrays,
2424
-hicpp-move-const-arg,
2525
-hicpp-no-array-decay,
26-
-hicpp-static-assert,
27-
-hicpp-uppercase-literal-suffix,
2826
-llvmlibc-callee-namespace,
2927
-llvmlibc-implementation-in-namespace,
3028
-llvmlibc-restrict-system-libc-headers,
3129
-misc-const-correctness,
3230
-modernize-avoid-c-arrays,
33-
-performance-move-const-arg,
3431
-performance-no-automatic-move,
3532
-performance-unnecessary-copy-initialization,
3633
-portability-simd-intrinsics,

‎sample/kf_6x2x0_vehicle_location.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ using no_input = void;
6767
{0.25, 0.5, 0.5, 0, 0, 0}, {0.5, 1, 1, 0, 0, 0}, {0.5, 1, 1, 0, 0, 0},
6868
{0, 0, 0, 0.25, 0.5, 0.5}, {0, 0, 0, 0.5, 1, 1}, {0, 0, 0, 0.5, 1, 1}};
6969
q *= 0.2 * 0.2;
70-
filter.q(std::move(q));
70+
filter.q(q);
7171

7272
// The state transition matrix F would be:
7373
filter.f(kalman::state_transition{{1, 1, 0.5, 0, 0, 0},

‎test/kalman_f.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,26 @@ namespace {
5858

5959
{
6060
const auto f{3.};
61-
filter.f(std::move(f));
62-
assert(filter.f() == 3);
63-
}
64-
65-
{
66-
const auto f{4.};
6761
filter.f(f);
68-
assert(filter.f() == 4);
69-
}
70-
71-
{
72-
const auto f{5.};
73-
filter.f(std::move(f));
74-
assert(filter.f() == 5);
62+
assert(filter.f() == 3);
7563
}
7664

7765
{
7866
const auto f{[]([[maybe_unused]] const kalman::state &x)
79-
-> kalman::state_transition { return 6.; }};
67+
-> kalman::state_transition { return 4.; }};
8068
filter.f(f);
81-
assert(filter.f() == 5);
69+
assert(filter.f() == 3);
8270
filter.predict();
83-
assert(filter.f() == 6);
71+
assert(filter.f() == 4);
8472
}
8573

8674
{
8775
const auto f{[]([[maybe_unused]] const kalman::state &x)
88-
-> kalman::state_transition { return 7.; }};
76+
-> kalman::state_transition { return 5.; }};
8977
filter.f(std::move(f));
90-
assert(filter.f() == 6);
78+
assert(filter.f() == 4);
9179
filter.predict();
92-
assert(filter.f() == 7);
80+
assert(filter.f() == 5);
9381
}
9482

9583
return 0;

‎test/kalman_f_5x4x3.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,9 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
7070

7171
assert(filter.f() == i5x5);
7272

73-
{
74-
const auto f{i5x5};
75-
filter.f(f);
76-
assert(filter.f() == i5x5);
77-
}
78-
7973
{
8074
const auto f{z5x5};
81-
filter.f(std::move(f));
75+
filter.f(f);
8276
assert(filter.f() == z5x5);
8377
}
8478

@@ -88,24 +82,18 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
8882
assert(filter.f() == i5x5);
8983
}
9084

91-
{
92-
const auto f{z5x5};
93-
filter.f(std::move(f));
94-
assert(filter.f() == z5x5);
95-
}
96-
9785
{
9886
const auto f{
9987
[]([[maybe_unused]] const kalman::state &x,
10088
[[maybe_unused]] const kalman::input &u,
10189
[[maybe_unused]] const int &i, [[maybe_unused]] const float &fp,
10290
[[maybe_unused]] const double &d) -> kalman::state_transition {
103-
return identity_v<matrix<5, 5>>;
91+
return zero_v<matrix<5, 5>>;
10492
}};
10593
filter.f(f);
106-
assert(filter.f() == z5x5);
107-
filter.predict(0, 0.F, 0., z3);
10894
assert(filter.f() == i5x5);
95+
filter.predict(0, 0.F, 0., z3);
96+
assert(filter.f() == z5x5);
10997
}
11098

11199
{
@@ -114,12 +102,12 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
114102
[[maybe_unused]] const kalman::input &u,
115103
[[maybe_unused]] const int &i, [[maybe_unused]] const float &fp,
116104
[[maybe_unused]] const double &d) -> kalman::state_transition {
117-
return zero_v<matrix<5, 5>>;
105+
return identity_v<matrix<5, 5>>;
118106
}};
119107
filter.f(std::move(f));
120-
assert(filter.f() == i5x5);
121-
filter.predict(0, 0.F, 0., z3);
122108
assert(filter.f() == z5x5);
109+
filter.predict(0, 0.F, 0., z3);
110+
assert(filter.f() == i5x5);
123111
}
124112

125113
return 0;

‎test/kalman_h.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,30 @@ namespace {
5858

5959
{
6060
const auto h{3.};
61-
filter.h(std::move(h));
62-
assert(filter.h() == 3);
63-
}
64-
65-
{
66-
const auto h{4.};
6761
filter.h(h);
68-
assert(filter.h() == 4);
69-
}
70-
71-
{
72-
const auto h{5.};
73-
filter.h(std::move(h));
74-
assert(filter.h() == 5);
62+
assert(filter.h() == 3);
7563
}
7664

7765
{
7866
const auto h{
7967
[]([[maybe_unused]] const kalman::state &x) -> kalman::output_model {
80-
return 6.;
68+
return 4.;
8169
}};
8270
filter.h(h);
83-
assert(filter.h() == 5);
71+
assert(filter.h() == 3);
8472
filter.update(0.);
85-
assert(filter.h() == 6);
73+
assert(filter.h() == 4);
8674
}
8775

8876
{
8977
const auto h{
9078
[]([[maybe_unused]] const kalman::state &x) -> kalman::output_model {
91-
return 7.;
79+
return 5.;
9280
}};
9381
filter.h(std::move(h));
94-
assert(filter.h() == 6);
82+
assert(filter.h() == 4);
9583
filter.update(0.);
96-
assert(filter.h() == 7);
84+
assert(filter.h() == 5);
9785
}
9886

9987
return 0;

‎test/kalman_h_5x4x3.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,9 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
6868

6969
assert(filter.h() == i4x5);
7070

71-
{
72-
const auto h{i4x5};
73-
filter.h(h);
74-
assert(filter.h() == i4x5);
75-
}
76-
7771
{
7872
const auto h{z4x5};
79-
filter.h(std::move(h));
73+
filter.h(h);
8074
assert(filter.h() == z4x5);
8175
}
8276

@@ -86,36 +80,30 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
8680
assert(filter.h() == i4x5);
8781
}
8882

89-
{
90-
const auto h{z4x5};
91-
filter.h(std::move(h));
92-
assert(filter.h() == z4x5);
93-
}
94-
9583
{
9684
const auto h{[]([[maybe_unused]] const kalman::state &x,
9785
[[maybe_unused]] const double &d,
9886
[[maybe_unused]] const float &f,
9987
[[maybe_unused]] const int &i) -> kalman::output_model {
100-
return identity_v<matrix<4, 5>>;
88+
return zero_v<matrix<4, 5>>;
10189
}};
10290
filter.h(h);
103-
assert(filter.h() == z4x5);
104-
filter.update(0., 0.F, 0, z4);
10591
assert(filter.h() == i4x5);
92+
filter.update(0., 0.F, 0, z4);
93+
assert(filter.h() == z4x5);
10694
}
10795

10896
{
10997
const auto h{[]([[maybe_unused]] const kalman::state &x,
11098
[[maybe_unused]] const double &d,
11199
[[maybe_unused]] const float &f,
112100
[[maybe_unused]] const int &i) -> kalman::output_model {
113-
return zero_v<matrix<4, 5>>;
101+
return identity_v<matrix<4, 5>>;
114102
}};
115103
filter.h(std::move(h));
116-
assert(filter.h() == i4x5);
117-
filter.update(0., 0.F, 0, z4);
118104
assert(filter.h() == z4x5);
105+
filter.update(0., 0.F, 0, z4);
106+
assert(filter.h() == i4x5);
119107
}
120108

121109
return 0;

0 commit comments

Comments
 (0)