mirror of https://github.com/odrling/Aegisub
More optimizations.
Originally committed to SVN as r2369.
This commit is contained in:
parent
2baf7bd2c4
commit
70e138bbf1
|
@ -163,8 +163,13 @@ void ActionModify::Execute(IModel& model)
|
||||||
ActionModifyBatch::ActionModifyBatch(std::vector<Entry> _entries, std::vector<shared_ptr<void> > _deltas, Selection _selection,const String &_section,bool _noTextFields)
|
ActionModifyBatch::ActionModifyBatch(std::vector<Entry> _entries, std::vector<shared_ptr<void> > _deltas, Selection _selection,const String &_section,bool _noTextFields)
|
||||||
: entries(_entries), deltas(_deltas), selection(_selection), section(_section), noTextFields(_noTextFields) {}
|
: entries(_entries), deltas(_deltas), selection(_selection), section(_section), noTextFields(_noTextFields) {}
|
||||||
|
|
||||||
|
ActionModifyBatch::ActionModifyBatch(Selection _selection,const String &_section,bool _noTextFields)
|
||||||
|
: selection(_selection), section(_section), noTextFields(_noTextFields) {}
|
||||||
|
|
||||||
Action ActionModifyBatch::GetAntiAction(const IModel& model) const
|
Action ActionModifyBatch::GetAntiAction(const IModel& model) const
|
||||||
{
|
{
|
||||||
|
// Old, slow method
|
||||||
|
if (false) {
|
||||||
// Get section
|
// Get section
|
||||||
Section sect = GetSection(model,section);
|
Section sect = GetSection(model,section);
|
||||||
size_t len = selection->GetCount();
|
size_t len = selection->GetCount();
|
||||||
|
@ -190,6 +195,41 @@ Action ActionModifyBatch::GetAntiAction(const IModel& model) const
|
||||||
return Action(new ActionModifyBatch(oldEntries,_deltas,selection,section,noTextFields));
|
return Action(new ActionModifyBatch(oldEntries,_deltas,selection,section,noTextFields));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// Get section
|
||||||
|
Section sect = GetSection(model,section);
|
||||||
|
size_t len = selection->GetCount();
|
||||||
|
|
||||||
|
// OK, this block warrants some explanation:
|
||||||
|
// Copying smart pointers around all the time is quite slow, so I just create them once and
|
||||||
|
// access the final copies.
|
||||||
|
ActionModifyBatch* antiPtr = new ActionModifyBatch(selection,section,noTextFields);
|
||||||
|
Action anti = Action(antiPtr);
|
||||||
|
std::vector<VoidPtr>& _deltas = antiPtr->deltas;
|
||||||
|
std::vector<Entry>& oldEntries = antiPtr->entries;
|
||||||
|
_deltas.resize(len);
|
||||||
|
oldEntries.resize(len);
|
||||||
|
|
||||||
|
// For each line...
|
||||||
|
for (size_t i=0;i<len;i++) {
|
||||||
|
// Get old entry
|
||||||
|
Entry oldEntry = sect->GetEntry(selection->GetLine(i));
|
||||||
|
|
||||||
|
// Try to get a delta
|
||||||
|
DeltaCoder deltaCoder = oldEntry->GetDeltaCoder();
|
||||||
|
if (deltaCoder) {
|
||||||
|
if (i < deltas.size() && deltas[i]) _deltas[i] = deltaCoder->EncodeReverseDelta(deltas[i],oldEntry);
|
||||||
|
_deltas[i] = deltaCoder->EncodeDelta(entries[i],oldEntry,!noTextFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the whole original line
|
||||||
|
else oldEntries[i] = oldEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
return anti;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ActionModifyBatch::Execute(IModel& model)
|
void ActionModifyBatch::Execute(IModel& model)
|
||||||
{
|
{
|
||||||
// Find the section to modify
|
// Find the section to modify
|
||||||
|
|
|
@ -93,6 +93,8 @@ namespace Athenasub {
|
||||||
const String section;
|
const String section;
|
||||||
bool noTextFields;
|
bool noTextFields;
|
||||||
|
|
||||||
|
ActionModifyBatch(Selection selection,const String §ion,bool noTextFields);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ActionModifyBatch(std::vector<Entry> entries,std::vector<VoidPtr> deltas,Selection selection,const String §ion,bool noTextFields);
|
ActionModifyBatch(std::vector<Entry> entries,std::vector<VoidPtr> deltas,Selection selection,const String §ion,bool noTextFields);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue