From 7d03479f41b9454d66d4ff82f8c6ed06b5ae57aa Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 5 Apr 2023 11:27:50 -0400 Subject: [PATCH] [Cleanup] Use constant reference and check for empty string properly in dbcore.cpp (#3203) # Notes - Passing by constant reference is more performant. - Checking for empty string with `!= '\0'` is more performant. - https://pvs-studio.com/en/docs/warnings/v805/ - https://pvs-studio.com/en/docs/warnings/v813/ --- common/dbcore.cpp | 4 ++-- common/dbcore.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/dbcore.cpp b/common/dbcore.cpp index 0bb641141..773fb882f 100644 --- a/common/dbcore.cpp +++ b/common/dbcore.cpp @@ -80,7 +80,7 @@ MySQLRequestResult DBcore::QueryDatabase(const std::string& query, bool retryOnF return r; } -bool DBcore::DoesTableExist(std::string table_name) +bool DBcore::DoesTableExist(const std::string& table_name) { auto results = QueryDatabase(fmt::format("SHOW TABLES LIKE '{}'", table_name)); @@ -136,7 +136,7 @@ MySQLRequestResult DBcore::QueryDatabase(const char *query, uint32 querylen, boo /** * Error logging */ - if (mysql_errno(mysql) > 0 && strlen(query) > 0) { + if (mysql_errno(mysql) > 0 && query[0] != '\0') { LogMySQLError("[{}] [{}]\n[{}]", mysql_errno(mysql), mysql_error(mysql), query); } diff --git a/common/dbcore.h b/common/dbcore.h index 7c5da95d8..6da00cb62 100644 --- a/common/dbcore.h +++ b/common/dbcore.h @@ -35,7 +35,7 @@ public: const std::string &GetOriginHost() const; void SetOriginHost(const std::string &origin_host); - bool DoesTableExist(std::string table_name); + bool DoesTableExist(const std::string& table_name); void SetMySQL(const DBcore &o) {