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/Utilities/Util.cpp | |
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/Utilities/Util.cpp')
-rwxr-xr-x | src/server/shared/Utilities/Util.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
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) |