mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 15:49:25 +01:00
Simplify std::copy
with fmt::format_to
Plus a few other memory allocation optimizations.
This commit is contained in:
parent
4c064de235
commit
ff6845288e
@ -10,6 +10,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -580,7 +581,7 @@ SharedContentMap::GetFilenameFromSHA1(const std::array<u8, 20>& sha1) const
|
|||||||
if (it == m_entries.end())
|
if (it == m_entries.end())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const std::string id_string(it->id.begin(), it->id.end());
|
const std::string_view id_string(reinterpret_cast<const char*>(it->id.data()), it->id.size());
|
||||||
return fmt::format("/shared1/{}.app", id_string);
|
return fmt::format("/shared1/{}.app", id_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,20 +597,22 @@ std::vector<std::array<u8, 20>> SharedContentMap::GetHashes() const
|
|||||||
|
|
||||||
std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
||||||
{
|
{
|
||||||
auto filename = GetFilenameFromSHA1(sha1);
|
if (auto filename = GetFilenameFromSHA1(sha1))
|
||||||
if (filename)
|
return *std::move(filename);
|
||||||
return *filename;
|
|
||||||
|
|
||||||
const std::string id = fmt::format("{:08x}", m_last_id);
|
Entry& entry = m_entries.emplace_back();
|
||||||
Entry entry;
|
static_assert(sizeof(m_last_id) == 4,
|
||||||
std::copy(id.cbegin(), id.cend(), entry.id.begin());
|
"'m_last_id' must be represented by 8 characters when formatted in hexadecimal.");
|
||||||
|
static_assert(std::tuple_size_v<decltype(entry.id)> == sizeof(m_last_id) * 2,
|
||||||
|
"'entry.id' must be a std::array capable of storing every nibble of 'm_last_id'.");
|
||||||
|
fmt::format_to(entry.id.data(), "{:08x}", m_last_id);
|
||||||
entry.sha1 = sha1;
|
entry.sha1 = sha1;
|
||||||
m_entries.push_back(entry);
|
|
||||||
|
|
||||||
WriteEntries();
|
WriteEntries();
|
||||||
filename = fmt::format("/shared1/{}.app", id);
|
|
||||||
m_last_id++;
|
m_last_id++;
|
||||||
return *filename;
|
|
||||||
|
const std::string_view id_string(reinterpret_cast<const char*>(entry.id.data()), entry.id.size());
|
||||||
|
return fmt::format("/shared1/{}.app", id_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SharedContentMap::DeleteSharedContent(const std::array<u8, 20>& sha1)
|
bool SharedContentMap::DeleteSharedContent(const std::array<u8, 20>& sha1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user