General: Use emplace_back where applicable

Same thing, less reading.
This commit is contained in:
Lioncash 2019-08-26 03:25:35 -04:00
parent 88c017926b
commit 176493c539
5 changed files with 31 additions and 19 deletions

View File

@ -505,13 +505,17 @@ amuse::LayerMapping LayersModel::_removeRow(int row) {
LayersModel::LayersModel(QObject* parent) : QAbstractTableModel(parent) {}
void LayersTableView::deleteSelection() {
QModelIndexList list = selectionModel()->selectedRows();
if (list.isEmpty())
const QModelIndexList list = selectionModel()->selectedRows();
if (list.isEmpty()) {
return;
}
std::vector<std::pair<amuse::LayerMapping, int>> data;
data.reserve(list.size());
for (QModelIndex idx : list)
data.push_back(std::make_pair(amuse::LayerMapping{}, idx.row()));
for (const QModelIndex idx : list) {
data.emplace_back(amuse::LayerMapping{}, idx.row());
}
std::sort(data.begin(), data.end(), [](const auto& a, const auto& b) { return a.second < b.second; });
g_MainWindow->pushUndoCommand(new LayerRowDelUndoCommand(static_cast<LayersModel*>(model())->m_node.get(),
data.size() > 1 ? tr("Delete Layers") : tr("Delete Layer"),
@ -582,12 +586,15 @@ void LayersEditor::rowsMoved(const QModelIndex& parent, int start, int end, cons
}
void LayersEditor::doAdd() {
QModelIndex idx = m_tableView.selectionModel()->currentIndex();
const QModelIndex idx = m_tableView.selectionModel()->currentIndex();
std::vector<std::pair<amuse::LayerMapping, int>> data;
if (!idx.isValid())
data.push_back(std::make_pair(amuse::LayerMapping{}, m_model.rowCount() - 1));
else
data.push_back(std::make_pair(amuse::LayerMapping{}, idx.row()));
if (idx.isValid()) {
data.emplace_back(amuse::LayerMapping{}, idx.row());
} else {
data.emplace_back(amuse::LayerMapping{}, m_model.rowCount() - 1);
}
g_MainWindow->pushUndoCommand(
new LayerRowAddUndoCommand(m_model.m_node.get(), tr("Add Layer"), &m_tableView, std::move(data)));
}

View File

@ -1152,13 +1152,17 @@ Qt::ItemFlags SetupModel::flags(const QModelIndex& index) const { return Qt::Ite
SetupModel::SetupModel(QObject* parent) : QAbstractTableModel(parent) {}
void PageTableView::deleteSelection() {
QModelIndexList list = selectionModel()->selectedRows();
if (list.isEmpty())
const QModelIndexList list = selectionModel()->selectedRows();
if (list.isEmpty()) {
return;
}
std::vector<std::pair<uint8_t, amuse::SongGroupIndex::PageEntry>> data;
data.reserve(list.size());
for (QModelIndex idx : list)
data.push_back(std::make_pair(model()->data(idx).toInt() - 1, amuse::SongGroupIndex::PageEntry{}));
for (const QModelIndex idx : list) {
data.emplace_back(model()->data(idx).toInt() - 1, amuse::SongGroupIndex::PageEntry{});
}
std::sort(data.begin(), data.end(), [](const auto& a, const auto& b) { return a.first < b.first; });
g_MainWindow->pushUndoCommand(new PageRowDelUndoCommand(
static_cast<PageModel*>(model())->m_node.get(),
@ -1413,7 +1417,7 @@ void SongGroupEditor::doAdd() {
}
std::vector<std::pair<uint8_t, amuse::SongGroupIndex::PageEntry>> data;
data.push_back(std::make_pair(prog, amuse::SongGroupIndex::PageEntry{}));
data.emplace_back(prog, amuse::SongGroupIndex::PageEntry{});
g_MainWindow->pushUndoCommand(
new PageRowAddUndoCommand(model->m_node.get(), tr("Add Page Entry"), table, std::move(data)));
@ -1423,7 +1427,7 @@ void SongGroupEditor::doAdd() {
g_MainWindow->projectModel()->setIdDatabases(model->m_node.get());
std::vector<std::tuple<amuse::SongId, std::string, std::array<amuse::SongGroupIndex::MIDISetup, 16>>> data;
auto songId = g_MainWindow->projectModel()->bootstrapSongId();
data.push_back(std::make_tuple(songId.first, songId.second, std::array<amuse::SongGroupIndex::MIDISetup, 16>{}));
data.emplace_back(songId.first, songId.second, std::array<amuse::SongGroupIndex::MIDISetup, 16>{});
g_MainWindow->pushUndoCommand(
new SetupRowAddUndoCommand(model->m_node.get(), tr("Add Setup Entry"), table, std::move(data)));
}

View File

@ -581,7 +581,7 @@ void SoundGroupEditor::doAdd() {
std::vector<std::tuple<amuse::SFXId, std::string, amuse::SFXGroupIndex::SFXEntry>> data;
amuse::SFXId sfxId = amuse::SFXId::CurNameDB->generateId(amuse::NameDB::Type::SFX);
std::string sfxName = amuse::SFXId::CurNameDB->generateName(sfxId, amuse::NameDB::Type::SFX);
data.push_back(std::make_tuple(sfxId, sfxName, amuse::SFXGroupIndex::SFXEntry{}));
data.emplace_back(sfxId, sfxName, amuse::SFXGroupIndex::SFXEntry{});
g_MainWindow->pushUndoCommand(
new SFXRowAddUndoCommand(m_sfxs.m_node.get(), tr("Add SFX Entry"), m_sfxTable, std::move(data)));
}

View File

@ -933,7 +933,7 @@ AudioGroupSampleDirectory::toGCNData(const AudioGroupDatabase& group) const {
entryDNA.m_sampleOff = sampleOffset;
sampleOffset += ROUND_UP_32(dataLen);
entryDNA.binarySize(adpcmOffset);
entries.push_back(std::make_pair(entryDNA, adpcmParms));
entries.emplace_back(entryDNA, adpcmParms);
}
}
adpcmOffset += 4;

View File

@ -330,8 +330,9 @@ std::string NameDB::generateName(ObjectId id, Type tp) {
std::string NameDB::generateDefaultName(Type tp) const { return generateName(generateId(tp), tp); }
std::string_view NameDB::registerPair(std::string_view str, ObjectId id) {
m_stringToId[std::string(str)] = id;
return m_idToString.insert(std::make_pair(id, str)).first->second;
auto string = std::string(str);
m_stringToId.insert_or_assign(string, id);
return m_idToString.emplace(id, std::move(string)).first->second;
}
std::string_view NameDB::resolveNameFromId(ObjectId id) const {