From a5caa95a4bbc0d457c9a036547781aaf8687e281 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Jun 2019 19:35:26 -0400 Subject: [PATCH] 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. --- Source/Core/Core/Analytics.cpp | 10 +++++----- Source/Core/Core/Analytics.h | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/Analytics.cpp b/Source/Core/Core/Analytics.cpp index 2b23d55c7a..d9e8835023 100644 --- a/Source/Core/Core/Analytics.cpp +++ b/Source/Core/Core/Analytics.cpp @@ -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(input.c_str()), input.size(), digest); + std::array digest; + const auto input = std::string{m_unique_id}.append(data); + mbedtls_sha1(reinterpret_cast(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"); diff --git a/Source/Core/Core/Analytics.h b/Source/Core/Core/Analytics.h index 194e1d1a18..c622469ee9 100644 --- a/Source/Core/Core/Analytics.h +++ b/Source/Core/Core/Analytics.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #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.