diff options
| author | linencloth <none@none> | 2010-10-21 16:56:51 +0200 |
|---|---|---|
| committer | linencloth <none@none> | 2010-10-21 16:56:51 +0200 |
| commit | d9d1ec3670ce4498b22025973fa126e5e3c2ab48 (patch) | |
| tree | 53f1ffd4ec3e3247f4b5af4bddf6207268b07eaf /src/server/shared | |
| parent | f275f8b4b580b48f8ff7804d2079d6cd83842cda (diff) | |
Core: optimize string splitting
- Mainly affects item loading performance
- Reduces guild loading time a lot
--HG--
branch : trunk
Diffstat (limited to 'src/server/shared')
| -rwxr-xr-x | src/server/shared/Database/MySQLConnection.h | 25 | ||||
| -rwxr-xr-x | src/server/shared/Utilities/Util.cpp | 36 | ||||
| -rwxr-xr-x | src/server/shared/Utilities/Util.h | 8 |
3 files changed, 43 insertions, 26 deletions
diff --git a/src/server/shared/Database/MySQLConnection.h b/src/server/shared/Database/MySQLConnection.h index ccd0dd515cd..56a670d07c1 100755 --- a/src/server/shared/Database/MySQLConnection.h +++ b/src/server/shared/Database/MySQLConnection.h @@ -32,19 +32,18 @@ struct MySQLConnectionInfo MySQLConnectionInfo() {} MySQLConnectionInfo(const std::string& infoString) { - Tokens tokens = StrSplit(infoString, ";"); - Tokens::iterator iter = tokens.begin(); - - if (iter != tokens.end()) - host = *iter++; - if (iter != tokens.end()) - port_or_socket = *iter++; - if (iter != tokens.end()) - user = *iter++; - if (iter != tokens.end()) - password = *iter++; - if (iter != tokens.end()) - database = *iter++; + Tokens tokens(infoString, ';'); + + if (tokens.size() != 5) + return; + + uint8 i = 0; + + host.assign(tokens[i++]); + port_or_socket.assign(tokens[i++]); + user.assign(tokens[i++]); + password.assign(tokens[i++]); + database.assign(tokens[i++]); } std::string user; diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index 6afbe92c0b7..371bd2c7e2b 100755 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -85,24 +85,38 @@ double rand_chance(void) } #endif -Tokens StrSplit(const std::string &src, const std::string &sep) +Tokens::Tokens(const std::string &src, const char sep, uint32 vectorReserve) { - Tokens r; - std::string s; - for (std::string::const_iterator i = src.begin(); i != src.end(); i++) + m_str = new char[src.length() + 1]; + memcpy(m_str, src.c_str(), src.length() + 1); + + if (vectorReserve) + reserve(vectorReserve); + + char* posold = m_str; + char* posnew = m_str; + + for (;;) { - if (sep.find(*i) != std::string::npos) + if (*posnew == sep) { - if (s.length()) r.push_back(s); - s = ""; + push_back(posold); + posold = posnew + 1; + + *posnew = 0x00; } - else + else if (*posnew == 0x00) { - s += *i; + // Hack like, but the old code accepted these kind of broken strings, + // so changing it would break other things + if (posold != posnew) + push_back(posold); + + break; } + + ++posnew; } - if (s.length()) r.push_back(s); - return r; } void stripLineInvisibleChars(std::string &str) diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h index c55da24fc80..8a49d7d9681 100755 --- a/src/server/shared/Utilities/Util.h +++ b/src/server/shared/Utilities/Util.h @@ -24,9 +24,13 @@ #include <string> #include <vector> -typedef std::vector<std::string> Tokens; +struct Tokens: public std::vector<char*> +{ + Tokens(const std::string &src, const char sep, uint32 vectorReserve = 0); + ~Tokens() { delete m_str; } -Tokens StrSplit(const std::string &src, const std::string &sep); + char* m_str; +}; void stripLineInvisibleChars(std::string &src); |
