rewrite parseIntegerList with better performance (#19629)

This commit is contained in:
John 2019-04-22 09:51:23 +08:00 committed by minggo
parent fd792813d2
commit 22a43fbc83
1 changed files with 13 additions and 16 deletions

View File

@ -79,23 +79,20 @@ SpriteFrameCache::~SpriteFrameCache()
void SpriteFrameCache::parseIntegerList(const std::string &string, std::vector<int> &res) void SpriteFrameCache::parseIntegerList(const std::string &string, std::vector<int> &res)
{ {
std::string delim(" ");
size_t n = std::count(string.begin(), string.end(), ' '); size_t n = std::count(string.begin(), string.end(), ' ');
res.resize(n+1); res.resize(n + 1);
size_t start = 0U; const char *cStr = string.c_str();
size_t end = string.find(delim); char *endptr;
int i=0; int i = 0;
while (end != std::string::npos) do {
{ long int val = strtol(cStr, &endptr, 10);
res[i++] = atoi(string.substr(start, end - start).c_str()); if (endptr == cStr)
start = end + delim.length(); return;
end = string.find(delim, start); res[i++] = static_cast<int>(val);
} cStr = endptr;
} while (*endptr != '\0');
res[i] = atoi(string.substr(start, end).c_str());
} }
void SpriteFrameCache::initializePolygonInfo(const Size &textureSize, void SpriteFrameCache::initializePolygonInfo(const Size &textureSize,