Skip to content

Commit

Permalink
rewrite parseIntegerList with better performance (cocos2d#19619)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoconut authored and huangwei1024 committed Jun 20, 2019
1 parent f69b51d commit d030b3b
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions cocos/2d/CCSpriteFrameCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,20 @@ SpriteFrameCache::~SpriteFrameCache()

void SpriteFrameCache::parseIntegerList(const std::string &string, std::vector<int> &res)
{
std::string delim(" ");

size_t n = std::count(string.begin(), string.end(), ' ');
res.resize(n+1);

size_t start = 0U;
size_t end = string.find(delim);

int i=0;
while (end != std::string::npos)
{
res[i++] = atoi(string.substr(start, end - start).c_str());
start = end + delim.length();
end = string.find(delim, start);
}

res[i] = atoi(string.substr(start, end).c_str());
res.resize(n + 1);

const char *cStr = string.c_str();
char *endptr;

int i = 0;
do {
long int val = strtol(cStr, &endptr, 10);
if (endptr == cStr)
return;
res[i++] = static_cast<int>(val);
cStr = endptr;
} while (*endptr != '\0');
}

void SpriteFrameCache::initializePolygonInfo(const Size &textureSize,
Expand Down

0 comments on commit d030b3b

Please sign in to comment.