From 93f107cb79aaa6ad4bc9a45872cb8b198a104fbd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 31 Mar 2020 13:23:19 -0400 Subject: [PATCH] STRG: Avoid unnecessary copies Makes several functions significantly less copy intensive. See previous commit for reason. --- DataSpec/DNAMP2/STRG.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/DataSpec/DNAMP2/STRG.cpp b/DataSpec/DNAMP2/STRG.cpp index 891c7b3da..30d0cb24a 100644 --- a/DataSpec/DNAMP2/STRG.cpp +++ b/DataSpec/DNAMP2/STRG.cpp @@ -67,8 +67,8 @@ void STRG::Enumerate(athena::io::IStreamWriter& writer) { writer.writeUint32Big(strCount); atUint32 offset = 0; - for (const std::pair>& lang : langs) { - lang.first.write(writer); + for (const auto& lang : langs) { + DNAFourCC{lang.first}.write(writer); writer.writeUint32Big(offset); offset += strCount * 4 + 4; atUint32 langStrCount = lang.second.size(); @@ -87,20 +87,22 @@ void STRG::Enumerate(athena::io::IStreamWriter& writer) { } atUint32 nameTableSz = names.size() * 8; - for (const std::pair& name : names) + for (const auto& name : names) { nameTableSz += name.first.size() + 1; + } writer.writeUint32Big(names.size()); writer.writeUint32Big(nameTableSz); offset = names.size() * 8; - for (const std::pair& name : names) { + for (const auto& name : names) { writer.writeUint32Big(offset); writer.writeInt32Big(name.second); offset += name.first.size() + 1; } - for (const std::pair& name : names) + for (const auto& name : names) { writer.writeString(name.first); + } - for (const std::pair>& lang : langs) { + for (const auto& lang : langs) { offset = strCount * 4; atUint32 langStrCount = lang.second.size(); for (atUint32 s = 0; s < strCount; ++s) { @@ -128,11 +130,12 @@ void STRG::Enumerate(size_t& __isz) { __isz += 8; __isz += names.size() * 8; - for (const std::pair& name : names) + for (const auto& name : names) { __isz += name.first.size() + 1; + } size_t strCount = STRG::count(); - for (const std::pair>& lang : langs) { + for (const auto& lang : langs) { atUint32 langStrCount = lang.second.size(); __isz += strCount * 4;