mirror of https://github.com/AxioDL/amuse.git
Merge pull request #24 from lioncash/emplace
General: Use emplace_back where applicable
This commit is contained in:
commit
8f810e571c
|
@ -508,13 +508,17 @@ amuse::LayerMapping LayersModel::_removeRow(int row) {
|
||||||
LayersModel::LayersModel(QObject* parent) : QAbstractTableModel(parent) {}
|
LayersModel::LayersModel(QObject* parent) : QAbstractTableModel(parent) {}
|
||||||
|
|
||||||
void LayersTableView::deleteSelection() {
|
void LayersTableView::deleteSelection() {
|
||||||
QModelIndexList list = selectionModel()->selectedRows();
|
const QModelIndexList list = selectionModel()->selectedRows();
|
||||||
if (list.isEmpty())
|
if (list.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<amuse::LayerMapping, int>> data;
|
std::vector<std::pair<amuse::LayerMapping, int>> data;
|
||||||
data.reserve(list.size());
|
data.reserve(list.size());
|
||||||
for (QModelIndex idx : list)
|
for (const QModelIndex idx : list) {
|
||||||
data.push_back(std::make_pair(amuse::LayerMapping{}, idx.row()));
|
data.emplace_back(amuse::LayerMapping{}, idx.row());
|
||||||
|
}
|
||||||
|
|
||||||
std::sort(data.begin(), data.end(), [](const auto& a, const auto& b) { return a.second < b.second; });
|
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(),
|
g_MainWindow->pushUndoCommand(new LayerRowDelUndoCommand(static_cast<LayersModel*>(model())->m_node.get(),
|
||||||
data.size() > 1 ? tr("Delete Layers") : tr("Delete Layer"),
|
data.size() > 1 ? tr("Delete Layers") : tr("Delete Layer"),
|
||||||
|
@ -585,12 +589,15 @@ void LayersEditor::rowsMoved(const QModelIndex& parent, int start, int end, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayersEditor::doAdd() {
|
void LayersEditor::doAdd() {
|
||||||
QModelIndex idx = m_tableView.selectionModel()->currentIndex();
|
const QModelIndex idx = m_tableView.selectionModel()->currentIndex();
|
||||||
std::vector<std::pair<amuse::LayerMapping, int>> data;
|
std::vector<std::pair<amuse::LayerMapping, int>> data;
|
||||||
if (!idx.isValid())
|
|
||||||
data.push_back(std::make_pair(amuse::LayerMapping{}, m_model.rowCount() - 1));
|
if (idx.isValid()) {
|
||||||
else
|
data.emplace_back(amuse::LayerMapping{}, idx.row());
|
||||||
data.push_back(std::make_pair(amuse::LayerMapping{}, idx.row()));
|
} else {
|
||||||
|
data.emplace_back(amuse::LayerMapping{}, m_model.rowCount() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
g_MainWindow->pushUndoCommand(
|
g_MainWindow->pushUndoCommand(
|
||||||
new LayerRowAddUndoCommand(m_model.m_node.get(), tr("Add Layer"), &m_tableView, std::move(data)));
|
new LayerRowAddUndoCommand(m_model.m_node.get(), tr("Add Layer"), &m_tableView, std::move(data)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1152,13 +1152,17 @@ Qt::ItemFlags SetupModel::flags(const QModelIndex& index) const { return Qt::Ite
|
||||||
SetupModel::SetupModel(QObject* parent) : QAbstractTableModel(parent) {}
|
SetupModel::SetupModel(QObject* parent) : QAbstractTableModel(parent) {}
|
||||||
|
|
||||||
void PageTableView::deleteSelection() {
|
void PageTableView::deleteSelection() {
|
||||||
QModelIndexList list = selectionModel()->selectedRows();
|
const QModelIndexList list = selectionModel()->selectedRows();
|
||||||
if (list.isEmpty())
|
if (list.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<uint8_t, amuse::SongGroupIndex::PageEntry>> data;
|
std::vector<std::pair<uint8_t, amuse::SongGroupIndex::PageEntry>> data;
|
||||||
data.reserve(list.size());
|
data.reserve(list.size());
|
||||||
for (QModelIndex idx : list)
|
for (const QModelIndex idx : list) {
|
||||||
data.push_back(std::make_pair(model()->data(idx).toInt() - 1, amuse::SongGroupIndex::PageEntry{}));
|
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; });
|
std::sort(data.begin(), data.end(), [](const auto& a, const auto& b) { return a.first < b.first; });
|
||||||
g_MainWindow->pushUndoCommand(new PageRowDelUndoCommand(
|
g_MainWindow->pushUndoCommand(new PageRowDelUndoCommand(
|
||||||
static_cast<PageModel*>(model())->m_node.get(),
|
static_cast<PageModel*>(model())->m_node.get(),
|
||||||
|
@ -1413,7 +1417,7 @@ void SongGroupEditor::doAdd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<uint8_t, amuse::SongGroupIndex::PageEntry>> data;
|
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(
|
g_MainWindow->pushUndoCommand(
|
||||||
new PageRowAddUndoCommand(model->m_node.get(), tr("Add Page Entry"), table, std::move(data)));
|
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());
|
g_MainWindow->projectModel()->setIdDatabases(model->m_node.get());
|
||||||
std::vector<std::tuple<amuse::SongId, std::string, std::array<amuse::SongGroupIndex::MIDISetup, 16>>> data;
|
std::vector<std::tuple<amuse::SongId, std::string, std::array<amuse::SongGroupIndex::MIDISetup, 16>>> data;
|
||||||
auto songId = g_MainWindow->projectModel()->bootstrapSongId();
|
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(
|
g_MainWindow->pushUndoCommand(
|
||||||
new SetupRowAddUndoCommand(model->m_node.get(), tr("Add Setup Entry"), table, std::move(data)));
|
new SetupRowAddUndoCommand(model->m_node.get(), tr("Add Setup Entry"), table, std::move(data)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -581,7 +581,7 @@ void SoundGroupEditor::doAdd() {
|
||||||
std::vector<std::tuple<amuse::SFXId, std::string, amuse::SFXGroupIndex::SFXEntry>> data;
|
std::vector<std::tuple<amuse::SFXId, std::string, amuse::SFXGroupIndex::SFXEntry>> data;
|
||||||
amuse::SFXId sfxId = amuse::SFXId::CurNameDB->generateId(amuse::NameDB::Type::SFX);
|
amuse::SFXId sfxId = amuse::SFXId::CurNameDB->generateId(amuse::NameDB::Type::SFX);
|
||||||
std::string sfxName = amuse::SFXId::CurNameDB->generateName(sfxId, 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(
|
g_MainWindow->pushUndoCommand(
|
||||||
new SFXRowAddUndoCommand(m_sfxs.m_node.get(), tr("Add SFX Entry"), m_sfxTable, std::move(data)));
|
new SFXRowAddUndoCommand(m_sfxs.m_node.get(), tr("Add SFX Entry"), m_sfxTable, std::move(data)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -933,7 +933,7 @@ AudioGroupSampleDirectory::toGCNData(const AudioGroupDatabase& group) const {
|
||||||
entryDNA.m_sampleOff = sampleOffset;
|
entryDNA.m_sampleOff = sampleOffset;
|
||||||
sampleOffset += ROUND_UP_32(dataLen);
|
sampleOffset += ROUND_UP_32(dataLen);
|
||||||
entryDNA.binarySize(adpcmOffset);
|
entryDNA.binarySize(adpcmOffset);
|
||||||
entries.push_back(std::make_pair(entryDNA, adpcmParms));
|
entries.emplace_back(entryDNA, adpcmParms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adpcmOffset += 4;
|
adpcmOffset += 4;
|
||||||
|
|
|
@ -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 NameDB::generateDefaultName(Type tp) const { return generateName(generateId(tp), tp); }
|
||||||
|
|
||||||
std::string_view NameDB::registerPair(std::string_view str, ObjectId id) {
|
std::string_view NameDB::registerPair(std::string_view str, ObjectId id) {
|
||||||
m_stringToId[std::string(str)] = id;
|
auto string = std::string(str);
|
||||||
return m_idToString.insert(std::make_pair(id, str)).first->second;
|
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 {
|
std::string_view NameDB::resolveNameFromId(ObjectId id) const {
|
||||||
|
|
Loading…
Reference in New Issue