Remove C++11'ism
authorRobin Gareus <robin@gareus.org>
Sun, 4 Nov 2018 14:37:46 +0000 (15:37 +0100)
committerRobin Gareus <robin@gareus.org>
Sun, 4 Nov 2018 14:37:46 +0000 (15:37 +0100)
While gnu-gcc had `std::map:at const` as non-standard extension
it is n/a for older gcc on OSX.

Surprisingly this const& p() const; performs a tad better as well, likely
due to different exception handling.

Perhaps it is also worth investigating boost::flat_map<> as replacement
for std::map<>, here. Our common case is just a single entry, so using
a std::vector emulated mapping might help.

libs/ardour/ardour/plugin_insert.h
libs/ardour/plugin_insert.cc

index 0a56373972ce0c378fb2a0392cc41d2097d6ca09..5460e25a14d2cbc47aac8c97210690fcf2cd6727 100644 (file)
@@ -367,7 +367,24 @@ private:
        /** details of the match currently being used */
        Match _match;
 
-       typedef std::map <uint32_t, ARDOUR::ChanMapping> PinMappings;
+       /* ordered map [plugin instance ID] => ARDOUR::ChanMapping
+        * TODO: consider replacing with boost::flat_map<> or std::vector<>.
+        */
+       class PinMappings : public std::map <uint32_t, ARDOUR::ChanMapping> {
+               public:
+                       /* this emulates C++11's  std::map::at()
+                        * return mapping for given plugin instance */
+                       inline ARDOUR::ChanMapping const& p (const uint32_t i) const {
+#ifndef NDEBUG
+                               const_iterator x = find (i);
+                               assert (x != end ());
+                               return x->second;
+#else
+                               return find(i)->second;
+#endif
+                       }
+       };
+
        PinMappings _in_map;
        PinMappings _out_map;
        ChanMapping _thru_map; // out-idx <=  in-idx
index b24d065b5bc3ad275334d3e49244bbb449d12c1a..f2ba4646654cb9189d7aa2142fb5c790c30ce65b 100644 (file)
@@ -860,11 +860,11 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                                continue;
                        }
                        bool valid;
-                       uint32_t first_idx = in_map.at(0).get (*t, 0, &valid);
+                       uint32_t first_idx = in_map.p(0).get (*t, 0, &valid);
                        assert (valid && first_idx == 0); // check_inplace ensures this
                        /* copy the first stream's buffer contents to the others */
                        for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
-                               uint32_t idx = in_map.at(0).get (*t, i, &valid);
+                               uint32_t idx = in_map.p(0).get (*t, i, &valid);
                                if (valid) {
                                        assert (idx == 0);
                                        bufs.get (*t, i).read_from (bufs.get (*t, first_idx), nframes, offset, offset);
@@ -950,7 +950,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                        for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                                for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) {
                                        bool valid;
-                                       uint32_t out_idx = out_map.at(pc).get (*t, out, &valid);
+                                       uint32_t out_idx = out_map.p(pc).get (*t, out, &valid);
                                        if (valid) {
                                                used_outputs.set (*t, out_idx, 1); // mark as used
                                        }
@@ -982,14 +982,14 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
 
                        ARDOUR::ChanMapping i_in_map (natural_input_streams());
-                       ARDOUR::ChanMapping i_out_map (out_map.at(pc));
+                       ARDOUR::ChanMapping i_out_map (out_map.p(pc));
                        ARDOUR::ChanCount mapped;
 
                        /* map inputs sequentially */
                        for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                                for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) {
                                        bool valid;
-                                       uint32_t in_idx = in_map.at(pc).get (*t, in, &valid);
+                                       uint32_t in_idx = in_map.p(pc).get (*t, in, &valid);
                                        uint32_t m = mapped.get (*t);
                                        if (valid) {
                                                inplace_bufs.get (*t, m).read_from (bufs.get (*t, in_idx), nframes, offset, offset);
@@ -1035,7 +1035,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                /* in-place processing */
                uint32_t pc = 0;
                for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
-                       if ((*i)->connect_and_run(bufs, start, end, speed, in_map.at(pc), out_map.at(pc), nframes, offset)) {
+                       if ((*i)->connect_and_run(bufs, start, end, speed, in_map.p(pc), out_map.p(pc), nframes, offset)) {
                                deactivate ();
                        }
                }