summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-17 00:42:38 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-17 00:57:16 +0100
commit9344a79233882ac278b3812b91b6edf874ef5d16 (patch)
treee5bd324104a9d8dcf1839de8a880845f8739a37a /src/utils
parent0e24b15a386d45f43cea76c1b8ad744728a3190e (diff)
downloadmanaserv-9344a79233882ac278b3812b91b6edf874ef5d16.tar.gz
manaserv-9344a79233882ac278b3812b91b6edf874ef5d16.tar.xz
manaserv-9344a79233882ac278b3812b91b6edf874ef5d16.zip
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
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/encryption.cpp4
-rw-r--r--src/utils/logger.cpp6
-rw-r--r--src/utils/sha256.cpp2
-rw-r--r--src/utils/stringfilter.cpp10
4 files changed, 10 insertions, 12 deletions
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;