From adec061dd8e9db17dea42f8f648fe3fab76e2609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 21 Mar 2020 16:27:43 +0100 Subject: [PATCH] byml: Avoid possible copies in binary parser See 1dd229b for an explanation of why this change is useful. --- src/byml.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/byml.cpp b/src/byml.cpp index b50aa11..4f7fe3e 100644 --- a/src/byml.cpp +++ b/src/byml.cpp @@ -177,7 +177,7 @@ class Parser { switch (type) { case NodeType::String: - return m_string_table.GetString(m_reader, *raw); + return Byml{m_string_table.GetString(m_reader, *raw)}; case NodeType::Binary: { const u32 data_offset = *raw; const u32 size = m_reader.Read(data_offset).value(); @@ -219,7 +219,7 @@ class Parser { const auto type = m_reader.Read(offset + 4 + i); result.emplace_back(ParseContainerChildNode(values_offset + 4 * i, type.value())); } - return result; + return Byml{std::move(result)}; } Byml ParseHashNode(u32 offset, u32 size) { @@ -231,7 +231,7 @@ class Parser { result.emplace(m_hash_key_table.GetString(m_reader, name_idx.value()), ParseContainerChildNode(entry_offset + 4, type.value())); } - return result; + return Byml{std::move(result)}; } Byml ParseContainerNode(u32 offset) {