Connection: Collapse emplace_back(), back() pairs

emplace_back() already returns a reference to the constructed member, so
we don't need to query it via back() again.
This commit is contained in:
Lioncash 2019-08-23 14:02:16 -04:00
parent cbcfdcb67a
commit 2d7dd9bf5b
1 changed files with 11 additions and 19 deletions

View File

@ -838,8 +838,7 @@ Mesh::Mesh(Connection& conn, HMDLTopology topologyIn, int skinSlotCount, bool us
Index matSetCount(conn); Index matSetCount(conn);
materialSets.reserve(matSetCount.val); materialSets.reserve(matSetCount.val);
for (uint32_t i = 0; i < matSetCount.val; ++i) { for (uint32_t i = 0; i < matSetCount.val; ++i) {
materialSets.emplace_back(); std::vector<Material>& materials = materialSets.emplace_back();
std::vector<Material>& materials = materialSets.back();
Index matCount(conn); Index matCount(conn);
materials.reserve(matCount.val); materials.reserve(matCount.val);
for (uint32_t j = 0; j < matCount.val; ++j) for (uint32_t j = 0; j < matCount.val; ++j)
@ -1172,8 +1171,7 @@ MapArea::Surface::Surface(Connection& conn) {
conn._readBuf(&borderCount, 4); conn._readBuf(&borderCount, 4);
borders.reserve(borderCount); borders.reserve(borderCount);
for (uint32_t i = 0; i < borderCount; ++i) { for (uint32_t i = 0; i < borderCount; ++i) {
borders.emplace_back(); std::pair<Index, Index>& idx = borders.emplace_back();
std::pair<Index, Index>& idx = borders.back();
conn._readBuf(&idx, 8); conn._readBuf(&idx, 8);
} }
} }
@ -1448,9 +1446,7 @@ Action::Action(Connection& conn) {
conn._readBuf(&aabbCount, 4); conn._readBuf(&aabbCount, 4);
subtypeAABBs.reserve(aabbCount); subtypeAABBs.reserve(aabbCount);
for (uint32_t i = 0; i < aabbCount; ++i) { for (uint32_t i = 0; i < aabbCount; ++i) {
subtypeAABBs.emplace_back(); subtypeAABBs.emplace_back(conn, conn);
subtypeAABBs.back().first.read(conn);
subtypeAABBs.back().second.read(conn);
// printf("AABB %s %d (%f %f %f) (%f %f %f)\n", name.c_str(), i, // printf("AABB %s %d (%f %f %f) (%f %f %f)\n", name.c_str(), i,
// float(subtypeAABBs.back().first.val.simd[0]), float(subtypeAABBs.back().first.val.simd[1]), // float(subtypeAABBs.back().first.val.simd[0]), float(subtypeAABBs.back().first.val.simd[1]),
// float(subtypeAABBs.back().first.val.simd[2]), float(subtypeAABBs.back().second.val.simd[0]), // float(subtypeAABBs.back().first.val.simd[2]), float(subtypeAABBs.back().second.val.simd[0]),
@ -1805,12 +1801,11 @@ std::vector<std::string> DataStream::getArmatureNames() {
m_parent->_readBuf(&armCount, 4); m_parent->_readBuf(&armCount, 4);
ret.reserve(armCount); ret.reserve(armCount);
for (uint32_t i = 0; i < armCount; ++i) { for (uint32_t i = 0; i < armCount; ++i) {
ret.emplace_back(); std::string& name = ret.emplace_back();
std::string& name = ret.back();
uint32_t bufSz; uint32_t bufSz;
m_parent->_readBuf(&bufSz, 4); m_parent->_readBuf(&bufSz, 4);
name.assign(bufSz, ' '); name.assign(bufSz, ' ');
m_parent->_readBuf(&name[0], bufSz); m_parent->_readBuf(name.data(), name.size());
} }
return ret; return ret;
@ -1834,12 +1829,11 @@ std::vector<std::string> DataStream::getSubtypeNames() {
m_parent->_readBuf(&subCount, 4); m_parent->_readBuf(&subCount, 4);
ret.reserve(subCount); ret.reserve(subCount);
for (uint32_t i = 0; i < subCount; ++i) { for (uint32_t i = 0; i < subCount; ++i) {
ret.emplace_back(); std::string& name = ret.emplace_back();
std::string& name = ret.back();
uint32_t bufSz; uint32_t bufSz;
m_parent->_readBuf(&bufSz, 4); m_parent->_readBuf(&bufSz, 4);
name.assign(bufSz, ' '); name.assign(bufSz, ' ');
m_parent->_readBuf(&name[0], bufSz); m_parent->_readBuf(name.data(), name.size());
} }
return ret; return ret;
@ -1863,12 +1857,11 @@ std::vector<std::string> DataStream::getActionNames() {
m_parent->_readBuf(&actCount, 4); m_parent->_readBuf(&actCount, 4);
ret.reserve(actCount); ret.reserve(actCount);
for (uint32_t i = 0; i < actCount; ++i) { for (uint32_t i = 0; i < actCount; ++i) {
ret.emplace_back(); std::string& name = ret.emplace_back();
std::string& name = ret.back();
uint32_t bufSz; uint32_t bufSz;
m_parent->_readBuf(&bufSz, 4); m_parent->_readBuf(&bufSz, 4);
name.assign(bufSz, ' '); name.assign(bufSz, ' ');
m_parent->_readBuf(&name[0], bufSz); m_parent->_readBuf(name.data(), name.size());
} }
return ret; return ret;
@ -1920,12 +1913,11 @@ std::vector<std::string> DataStream::getAttachmentNames() {
m_parent->_readBuf(&attCount, 4); m_parent->_readBuf(&attCount, 4);
ret.reserve(attCount); ret.reserve(attCount);
for (uint32_t i = 0; i < attCount; ++i) { for (uint32_t i = 0; i < attCount; ++i) {
ret.emplace_back(); std::string& name = ret.emplace_back();
std::string& name = ret.back();
uint32_t bufSz; uint32_t bufSz;
m_parent->_readBuf(&bufSz, 4); m_parent->_readBuf(&bufSz, 4);
name.assign(bufSz, ' '); name.assign(bufSz, ' ');
m_parent->_readBuf(&name[0], bufSz); m_parent->_readBuf(name.data(), name.size());
} }
return ret; return ret;