Simplify and speed up AssFile's copy constructor and assignment operator.

Originally committed to SVN as r4565.
This commit is contained in:
Thomas Goyne 2010-06-22 00:03:33 +00:00
parent 7958f85ef3
commit a40b9c4b91
3 changed files with 15 additions and 14 deletions

View File

@ -33,8 +33,6 @@
/// @brief Class for dialogue lines in subtitles /// @brief Class for dialogue lines in subtitles
/// @ingroup subs_storage /// @ingroup subs_storage
////////////
// Includes
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
@ -66,7 +64,8 @@ AssDialogue::AssDialogue()
} }
AssDialogue::AssDialogue(AssDialogue const& that) AssDialogue::AssDialogue(AssDialogue const& that)
: Comment(that.Comment) : AssEntry()
, Comment(that.Comment)
, Layer(that.Layer) , Layer(that.Layer)
, Start(that.Start) , Start(that.Start)
, End(that.End) , End(that.End)

View File

@ -36,6 +36,7 @@
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
#include <algorithm>
#include <fstream> #include <fstream>
#include <list> #include <list>
@ -276,7 +277,7 @@ bool AssFile::CanSave() {
// I strongly advice you against touching this function unless you know what you're doing; // I strongly advice you against touching this function unless you know what you're doing;
// even moving things out of order might break ASS parsing - AMZ. // even moving things out of order might break ASS parsing - AMZ.
void AssFile::AddLine (wxString data,wxString group,int &version,wxString *outGroup) { void AssFile::AddLine(wxString data,wxString group,int &version,wxString *outGroup) {
// Group // Group
AssEntry *entry = NULL; AssEntry *entry = NULL;
wxString origGroup = group; wxString origGroup = group;
@ -450,18 +451,18 @@ void AssFile::LoadDefault (bool defline) {
loaded = true; loaded = true;
} }
AssFile::AssFile (AssFile &from) { AssFile::AssFile (const AssFile &from) {
using std::list;
// Copy standard variables
filename = from.filename; filename = from.filename;
loaded = from.loaded; loaded = from.loaded;
Modified = from.Modified; Modified = from.Modified;
std::transform(from.Line.begin(), from.Line.end(), std::back_inserter(Line), std::mem_fun(&AssEntry::Clone));
// Copy lines }
for (list<AssEntry*>::iterator cur=from.Line.begin();cur!=from.Line.end();cur++) { AssFile& AssFile::operator=(AssFile from) {
Line.push_back((*cur)->Clone()); filename = from.filename;
} loaded = from.loaded;
Modified = from.Modified;
std::swap(Line, from.Line);
return *this;
} }
void AssFile::InsertStyle (AssStyle *style) { void AssFile::InsertStyle (AssStyle *style) {

View File

@ -90,7 +90,8 @@ public:
bool loaded; bool loaded;
AssFile(); AssFile();
AssFile(AssFile &from); AssFile(const AssFile &from);
AssFile& operator=(AssFile from);
~AssFile(); ~AssFile();
/// Does the file have unsaved changes? /// Does the file have unsaved changes?