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
/// @ingroup subs_storage
////////////
// Includes
#include "config.h"
#ifndef AGI_PRE
@ -66,7 +64,8 @@ AssDialogue::AssDialogue()
}
AssDialogue::AssDialogue(AssDialogue const& that)
: Comment(that.Comment)
: AssEntry()
, Comment(that.Comment)
, Layer(that.Layer)
, Start(that.Start)
, End(that.End)

View File

@ -36,6 +36,7 @@
#include "config.h"
#ifndef AGI_PRE
#include <algorithm>
#include <fstream>
#include <list>
@ -276,7 +277,7 @@ bool AssFile::CanSave() {
// 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.
void AssFile::AddLine (wxString data,wxString group,int &version,wxString *outGroup) {
void AssFile::AddLine(wxString data,wxString group,int &version,wxString *outGroup) {
// Group
AssEntry *entry = NULL;
wxString origGroup = group;
@ -450,18 +451,18 @@ void AssFile::LoadDefault (bool defline) {
loaded = true;
}
AssFile::AssFile (AssFile &from) {
using std::list;
// Copy standard variables
AssFile::AssFile (const AssFile &from) {
filename = from.filename;
loaded = from.loaded;
Modified = from.Modified;
// Copy lines
for (list<AssEntry*>::iterator cur=from.Line.begin();cur!=from.Line.end();cur++) {
Line.push_back((*cur)->Clone());
}
std::transform(from.Line.begin(), from.Line.end(), std::back_inserter(Line), std::mem_fun(&AssEntry::Clone));
}
AssFile& AssFile::operator=(AssFile from) {
filename = from.filename;
loaded = from.loaded;
Modified = from.Modified;
std::swap(Line, from.Line);
return *this;
}
void AssFile::InsertStyle (AssStyle *style) {

View File

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