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

View File

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