aboutsummaryrefslogtreecommitdiffstats
path: root/gr-audio
diff options
context:
space:
mode:
authorThomas Habets <habets@google.com>2019-11-20 12:30:19 +0000
committerMartin Braun <martin.braun@ettus.com>2020-01-04 22:35:12 -0800
commit27a466a9c8a03392270fadde9e5bafef5c062e61 (patch)
treeb7b8ce04ef2b95cb663fc06faad4a866062007e6 /gr-audio
parentSimpleXMLRPCServer was moved in Python3 (diff)
downloadgnuradio-27a466a9c8a03392270fadde9e5bafef5c062e61.tar.xz
gnuradio-27a466a9c8a03392270fadde9e5bafef5c062e61.zip
Replace many `const` variables with `constexpr`
constexpr is like const but (for variables) guarantees evaluation at compile time (as opposed to runtime). Likely this change will do nothing on its own (though it could, since it gives the compiler more information). But it still has benefits. It allows programmer to know that initialization is not expensive (it was done at compile time), and reduces risk of a refactoring regressing the compiletimeness. Runtime initialization can be nonobvious in larger codebases. E.g.: struct S { static int foo(); }; const int bar = S::foo(); // Called and initialized at *runtime*. int S::foo() { return 10; } With constexpr: struct S { static constexpr int foo(); }; constexpr int bar = S::foo(); // Error: used before definition. constexpr int S::foo() { return 10; } Initializing at runtime is not just startup costs, but also can save memory since it'll end up in a R/O section of a binary and therefore doesn't need to be swapped out, but can be shared (in the mmap() sense of the word).
Diffstat (limited to 'gr-audio')
-rw-r--r--gr-audio/lib/jack/jack_sink.h2
-rw-r--r--gr-audio/lib/jack/jack_source.h2
2 files changed, 2 insertions, 2 deletions
diff --git a/gr-audio/lib/jack/jack_sink.h b/gr-audio/lib/jack/jack_sink.h
index 6c2ad24ba..60b501c9b 100644
--- a/gr-audio/lib/jack/jack_sink.h
+++ b/gr-audio/lib/jack/jack_sink.h
@@ -54,7 +54,7 @@ class jack_sink : public sink
std::string d_device_name;
jack_client_t* d_jack_client;
- static const int MAX_PORTS = 10;
+ static constexpr int MAX_PORTS = 10;
int d_portcount;
jack_port_t* d_jack_output_port[MAX_PORTS];
jack_ringbuffer_t* d_ringbuffer[MAX_PORTS];
diff --git a/gr-audio/lib/jack/jack_source.h b/gr-audio/lib/jack/jack_source.h
index e9a93a656..664a68d87 100644
--- a/gr-audio/lib/jack/jack_source.h
+++ b/gr-audio/lib/jack/jack_source.h
@@ -54,7 +54,7 @@ class jack_source : public source
std::string d_device_name;
jack_client_t* d_jack_client;
- static const int MAX_PORTS = 10;
+ static constexpr int MAX_PORTS = 10;
int d_portcount;
jack_port_t* d_jack_input_port[MAX_PORTS];
jack_ringbuffer_t* d_ringbuffer[MAX_PORTS];