From 9344a79233882ac278b3812b91b6edf874ef5d16 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 17 Mar 2011 00:42:38 +0100 Subject: Micro-optimizations related to std::string * Rely on the fact that a std::string is empty by default * Use std::string::empty() rather than comparing to "" * Construct with std::string() rather than from "" Reviewed-by: Bertram --- src/utils/encryption.cpp | 4 +--- src/utils/logger.cpp | 6 +++--- src/utils/sha256.cpp | 2 +- src/utils/stringfilter.cpp | 10 +++++----- 4 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src/utils') diff --git a/src/utils/encryption.cpp b/src/utils/encryption.cpp index 1a7cfb4..9062248 100644 --- a/src/utils/encryption.cpp +++ b/src/utils/encryption.cpp @@ -46,7 +46,7 @@ static char getRandomCharacter() */ std::string createRandomPassword() { - std::string result = ""; + std::string result; // Ititializing random seed. srand(time(NULL)); @@ -55,9 +55,7 @@ std::string createRandomPassword() int characterNumber = (rand() % 10) + 20; for (int a = 1; a < characterNumber; a++) - { result += getRandomCharacter(); - } return result; } diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp index d3f8241..e5ceb9b 100644 --- a/src/utils/logger.cpp +++ b/src/utils/logger.cpp @@ -36,7 +36,7 @@ namespace utils /** Log file. */ static std::ofstream mLogFile; /** current log filename */ -std::string Logger::mFilename = ""; +std::string Logger::mFilename; /** Timestamp flag. */ bool Logger::mHasTimestamp = true; /** Tee mode flag. */ @@ -50,13 +50,13 @@ long Logger::mMaxFileSize = 1024; // 1 Mb /** Switch log file each day. */ bool Logger::mSwitchLogEachDay = false; /** Last call date */ -static std::string mLastCallDate = ""; +static std::string mLastCallDate; /** * Old date * For code simplificatiion, the old Date is kept separate * from the last call date. */ -static std::string mOldDate = ""; +static std::string mOldDate; /** * Check whether the day has changed since the last call. diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp index ba6a507..102171e 100644 --- a/src/utils/sha256.cpp +++ b/src/utils/sha256.cpp @@ -263,7 +263,7 @@ std::string SHA256Hash(const char *src, int len) SHA256Final(&ctx, bytehash); // Convert it to hex const char* hxc = "0123456789abcdef"; - std::string hash = ""; + std::string hash; for (int i = 0; i < SHA256_DIGEST_SIZE; i++) { hash += hxc[bytehash[i] / 16]; diff --git a/src/utils/stringfilter.cpp b/src/utils/stringfilter.cpp index 617da90..b48d267 100644 --- a/src/utils/stringfilter.cpp +++ b/src/utils/stringfilter.cpp @@ -43,13 +43,13 @@ bool StringFilter::loadSlangFilterList() { mInitialized = false; - std::string slangsList = Configuration::getValue("SlangsList", ""); - if (slangsList != "") { + const std::string slangsList = Configuration::getValue("SlangsList", + std::string()); + if (!slangsList.empty()) { std::istringstream iss(slangsList); std::string tmp; - while (getline(iss, tmp, ',')) { + while (getline(iss, tmp, ',')) mSlangs.push_back(tmp); - } mInitialized = true; } @@ -59,7 +59,7 @@ bool StringFilter::loadSlangFilterList() void StringFilter::writeSlangFilterList() { // Write the list to config - std::string slangsList = ""; + std::string slangsList; for (SlangIterator i = mSlangs.begin(); i != mSlangs.end(); ) { slangsList += *i; -- cgit