Core/Analytics: Use std::string_view where applicable

In these cases, the strings are treated as views anyways, so we can use
them here to avoid potential allocations.
This commit is contained in:
Lioncash 2019-06-03 19:35:26 -04:00
parent 2c2b9690bb
commit a5caa95a4b
2 changed files with 8 additions and 7 deletions

View File

@ -101,11 +101,11 @@ void DolphinAnalytics::GenerateNewIdentity()
SConfig::GetInstance().SaveSettings();
}
std::string DolphinAnalytics::MakeUniqueId(const std::string& data)
std::string DolphinAnalytics::MakeUniqueId(std::string_view data)
{
u8 digest[20];
std::string input = m_unique_id + data;
mbedtls_sha1(reinterpret_cast<const u8*>(input.c_str()), input.size(), digest);
std::array<u8, 20> digest;
const auto input = std::string{m_unique_id}.append(data);
mbedtls_sha1(reinterpret_cast<const u8*>(input.c_str()), input.size(), digest.data());
// Convert to hex string and truncate to 64 bits.
std::string out;
@ -116,7 +116,7 @@ std::string DolphinAnalytics::MakeUniqueId(const std::string& data)
return out;
}
void DolphinAnalytics::ReportDolphinStart(const std::string& ui_type)
void DolphinAnalytics::ReportDolphinStart(std::string_view ui_type)
{
Common::AnalyticsReportBuilder builder(m_base_builder);
builder.AddData("type", "dolphin-start");

View File

@ -8,6 +8,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <vector>
#include "Common/Analytics.h"
@ -49,7 +50,7 @@ public:
void GenerateNewIdentity();
// Reports a Dolphin start event.
void ReportDolphinStart(const std::string& ui_type);
void ReportDolphinStart(std::string_view ui_type);
// Generates a base report for a "Game start" event. Also preseeds the
// per-game base data.
@ -88,7 +89,7 @@ private:
// Returns a unique ID derived on the global unique ID, hashed with some
// report-specific data. This avoid correlation between different types of
// events.
std::string MakeUniqueId(const std::string& data);
std::string MakeUniqueId(std::string_view data);
// Unique ID. This should never leave the application. Only used derived
// values created by MakeUniqueId.