Prevent copy-construction of sources to be destroyed list
authorRobin Gareus <robin@gareus.org>
Wed, 25 Dec 2019 16:57:10 +0000 (17:57 +0100)
committerRobin Gareus <robin@gareus.org>
Wed, 25 Dec 2019 16:57:10 +0000 (17:57 +0100)
destroy_sources () is only called from Session::remove_last_capture ().
The list of sources to be destroyed is the local scope of that method
and will hold a reference to the object.
copy-construct the list and removing elements one by one from the
copy is only unnecessary overhead.

libs/ardour/ardour/session.h
libs/ardour/session.cc

index 14eecbae6afc1b5c0dcf2904e652b5d8cd66c7bf..9326c9b948b2c591213fb29aff906b7b7abc199f 100644 (file)
@@ -805,7 +805,7 @@ public:
        int  cleanup_sources (CleanupReport&);
        int  cleanup_trash_sources (CleanupReport&);
 
-       int destroy_sources (std::list<boost::shared_ptr<Source> >);
+       int destroy_sources (std::list<boost::shared_ptr<Source> > const&);
 
        int remove_last_capture ();
        void get_last_capture_sources (std::list<boost::shared_ptr<Source> >&);
index 09e5634f5e5b6fff958a3b8c510a95be13018652..499cf733792f0873b6296216cc3525e62b874959 100644 (file)
@@ -4242,11 +4242,11 @@ Session::find_whole_file_parent (boost::shared_ptr<Region const> child) const
 }
 
 int
-Session::destroy_sources (list<boost::shared_ptr<Source> > srcs)
+Session::destroy_sources (list<boost::shared_ptr<Source> > const& srcs)
 {
        set<boost::shared_ptr<Region> > relevant_regions;
 
-       for (list<boost::shared_ptr<Source> >::iterator s = srcs.begin(); s != srcs.end(); ++s) {
+       for (list<boost::shared_ptr<Source> >::const_iterator s = srcs.begin(); s != srcs.end(); ++s) {
                RegionFactory::get_regions_using_source (*s, relevant_regions);
        }
 
@@ -4267,7 +4267,7 @@ Session::destroy_sources (list<boost::shared_ptr<Source> > srcs)
                r = tmp;
        }
 
-       for (list<boost::shared_ptr<Source> >::iterator s = srcs.begin(); s != srcs.end(); ) {
+       for (list<boost::shared_ptr<Source> >::const_iterator s = srcs.begin(); s != srcs.end(); ++s) {
 
                {
                        Glib::Threads::Mutex::Lock ls (source_lock);
@@ -4278,8 +4278,6 @@ Session::destroy_sources (list<boost::shared_ptr<Source> > srcs)
                (*s)->mark_for_remove ();
                (*s)->drop_references ();
                SourceRemoved(*s);
-
-               s = srcs.erase (s);
        }
 
        return 0;