]> git.tdb.fi Git - r2c2.git/commitdiff
Store zone blocks in order and use add_tracks to load them
authorMikko Rasa <tdb@tdb.fi>
Fri, 20 Feb 2015 15:41:53 +0000 (17:41 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 20 Feb 2015 15:41:53 +0000 (17:41 +0200)
source/libr2c2/zone.cpp

index 30b60e99aa65865a0960afc113e3d5f5fedfbd7f..8b6c95f9c9af2fd0911c956e76fe44e15cfb0362 100644 (file)
@@ -62,12 +62,19 @@ void Zone::save(list<DataFile::Statement> &st) const
        if(number)
                st.push_back((DataFile::Statement("number"), number));
 
-       set<unsigned> block_ids;
-       for(TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               block_ids.insert((*i)->get_block().get_id());
-
-       for(set<unsigned>::const_iterator i=block_ids.begin(); i!=block_ids.end(); ++i)
-               st.push_back((DataFile::Statement("block"), *i));
+       unsigned last_block = 0;
+       TrackIter iter = ends[0].reverse();
+       while(iter && tracks.count(iter.track()))
+       {
+               unsigned block_id = iter->get_block().get_id();
+               if(block_id!=last_block)
+               {
+                       st.push_back((DataFile::Statement("block"), block_id));
+                       last_block = block_id;
+               }
+
+               iter = next_iter(iter);
+       }
 }
 
 DataFile::Statement Zone::save_reference() const
@@ -93,8 +100,7 @@ void Zone::Loader::finish()
 void Zone::Loader::block(unsigned b)
 {
        Block &blk = obj.layout.get_block(b);
-       const set<Track *> &btracks = blk.get_tracks();
-       obj.tracks.insert(btracks.begin(), btracks.end());
+       obj.add_tracks(blk.get_tracks());
 }
 
 } // namespace R2C2