mirror of https://github.com/axmolengine/axmol.git
rewrite parseIntegerList with better performance (#19629)
This commit is contained in:
parent
fd792813d2
commit
22a43fbc83
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue