Skip to content
Permalink
Browse files

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.
  • Loading branch information...
lioncash committed Jun 3, 2019
1 parent 2c2b969 commit a5caa95a4bbc0d457c9a036547781aaf8687e281
Showing with 8 additions and 7 deletions.
  1. +5 −5 Source/Core/Core/Analytics.cpp
  2. +3 −2 Source/Core/Core/Analytics.h
@@ -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");
@@ -8,6 +8,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <vector>

#include "Common/Analytics.h"
@@ -49,7 +50,7 @@ class DolphinAnalytics
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 @@ class DolphinAnalytics
// 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.

0 comments on commit a5caa95

Please sign in to comment.
You can’t perform that action at this time.