From 0a92bc147f91f3ecacdf66d995f01f9577107a86 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 15 Feb 2018 09:06:13 +0100 Subject: clean up "static" and "constexpr" types - use `static constexpr inline' to avoid requiring explicit declarations in object code - use `const Foo* const' to maybe put into readonly binary segment (at least for ELF DSOs) - `constexpr' in function scope has storage, avoid `static' - don't use `constexpr' where there's no advantage, like arrays We'd like to avoid overhead of atomic initialization for each function call. No idea how `static constexpr' requiring storage in the standard plays with atomic initialization requirement. Hearsay points that `constexpr' without `static' in block scope behaves more to our liking. It's all hazy though. I'm not 100% sure if `static inline constexpr' has any storage. Hopefully none, like a #define, and stuff bigger than registers gets coalesced within the same module, with small stuff being immediates. --- proto-mouse/ftnoir_protocol_mouse.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'proto-mouse') diff --git a/proto-mouse/ftnoir_protocol_mouse.cpp b/proto-mouse/ftnoir_protocol_mouse.cpp index ccc91e33..b4b27ea9 100644 --- a/proto-mouse/ftnoir_protocol_mouse.cpp +++ b/proto-mouse/ftnoir_protocol_mouse.cpp @@ -17,6 +17,12 @@ # define MOUSEEVENTF_MOVE_NOCOALESCE 0x2000 #endif +static const double invert[] = +{ + 1., 1., 1., + 1., -1., 1. +}; + void mouse::pose(const double *headpose) { const int axis_x = s.Mouse_X - 1; @@ -24,12 +30,6 @@ void mouse::pose(const double *headpose) int mouse_x = 0, mouse_y = 0; - static constexpr double invert[] = - { - 1., 1., 1., - 1., -1., 1. - }; - if (axis_x >= 0 && axis_x < 6) { mouse_x = get_value(headpose[axis_x] * invert[axis_x], @@ -76,7 +76,7 @@ int mouse::get_delta(int val, int prev) int mouse::get_value(double val, double sensitivity, bool is_rotation) { - static constexpr double sgn[] = { 1e-2, 1 }; + constexpr double sgn[] = { 1e-2, 1 }; constexpr double c = 1e-1; return iround(val * c * sensitivity * sgn[unsigned(is_rotation)]); -- cgit v1.2.3