Update CCGroupCommand.cpp

add a vector container for save unused id.
traversal unordered_map is too slow, use vector to replace it
This commit is contained in:
G17hao 2015-01-20 19:28:30 +08:00
parent e849243894
commit 29c4f83fd8
1 changed files with 6 additions and 6 deletions

View File

@ -49,13 +49,12 @@ bool GroupCommandManager::init()
int GroupCommandManager::getGroupID()
{
//Reuse old id
for(auto it = _groupMapping.begin(); it != _groupMapping.end(); ++it)
if (!_unusedIDs.empty())
{
if(!it->second)
{
_groupMapping[it->first] = true;
return it->first;
}
int groupID = *_unusedIDs.rbegin();
_unusedIDs.pop_back();
_groupMapping[groupID] = true;
return groupID;
}
//Create new ID
@ -69,6 +68,7 @@ int GroupCommandManager::getGroupID()
void GroupCommandManager::releaseGroupID(int groupID)
{
_groupMapping[groupID] = false;
_unusedIDs.push_back(groupID);
}
GroupCommand::GroupCommand()