Skip to content

Commit

Permalink
byml: Avoid possible copies in binary parser
Browse files Browse the repository at this point in the history
See 1dd229b for an explanation of why this change is useful.
  • Loading branch information
leoetlino committed Mar 21, 2020
1 parent 09aaab1 commit adec061
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/byml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>(data_offset).value();
Expand Down Expand Up @@ -219,7 +219,7 @@ class Parser {
const auto type = m_reader.Read<NodeType>(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) {
Expand All @@ -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) {
Expand Down

0 comments on commit adec061

Please sign in to comment.