diff --git a/Source/Core/Common/Analytics.cpp b/Source/Core/Common/Analytics.cpp index ed48d15188..63903767ba 100644 --- a/Source/Core/Common/Analytics.cpp +++ b/Source/Core/Common/Analytics.cpp @@ -76,15 +76,19 @@ AnalyticsReportBuilder::AnalyticsReportBuilder() m_report.push_back(WIRE_FORMAT_VERSION); } -void AnalyticsReportBuilder::AppendSerializedValue(std::string* report, const std::string& v) +void AnalyticsReportBuilder::AppendSerializedValue(std::string* report, std::string_view v) { AppendType(report, TypeId::STRING); AppendBytes(report, reinterpret_cast(v.data()), static_cast(v.size())); } +// We can't remove this overload despite the string_view overload due to the fact that +// pointers can implicitly convert to bool, so if we removed the overload, then all +// const char strings passed in would begin forwarding to the bool overload, +// which is definitely not what we want to occur. void AnalyticsReportBuilder::AppendSerializedValue(std::string* report, const char* v) { - AppendSerializedValue(report, std::string(v)); + AppendSerializedValue(report, std::string_view(v)); } void AnalyticsReportBuilder::AppendSerializedValue(std::string* report, bool v) diff --git a/Source/Core/Common/Analytics.h b/Source/Core/Common/Analytics.h index dc1ab8c599..a14150e21c 100644 --- a/Source/Core/Common/Analytics.h +++ b/Source/Core/Common/Analytics.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -86,7 +87,7 @@ public: } template - AnalyticsReportBuilder& AddData(const std::string& key, const T& value) + AnalyticsReportBuilder& AddData(std::string_view key, const T& value) { std::lock_guard lk{m_lock}; AppendSerializedValue(&m_report, key); @@ -95,7 +96,7 @@ public: } template - AnalyticsReportBuilder& AddData(const std::string& key, const std::vector& value) + AnalyticsReportBuilder& AddData(std::string_view key, const std::vector& value) { std::lock_guard lk{m_lock}; AppendSerializedValue(&m_report, key); @@ -117,7 +118,7 @@ public: } protected: - static void AppendSerializedValue(std::string* report, const std::string& v); + static void AppendSerializedValue(std::string* report, std::string_view v); static void AppendSerializedValue(std::string* report, const char* v); static void AppendSerializedValue(std::string* report, bool v); static void AppendSerializedValue(std::string* report, u64 v);