optimize CCTextureCache::removeUnusedCache()

This commit is contained in:
minggo 2012-04-28 11:34:13 +08:00
parent 53733091d3
commit cbfe1e0d0c
1 changed files with 28 additions and 0 deletions

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include <string> #include <string>
#include <cctype> #include <cctype>
#include <queue> #include <queue>
#include <list>
#include "CCTextureCache.h" #include "CCTextureCache.h"
#include "CCTexture2D.h" #include "CCTexture2D.h"
#include "ccMacros.h" #include "ccMacros.h"
@ -541,6 +542,7 @@ void CCTextureCache::removeAllTextures()
void CCTextureCache::removeUnusedTextures() void CCTextureCache::removeUnusedTextures()
{ {
/*
CCDictElement* pElement = NULL; CCDictElement* pElement = NULL;
CCDICT_FOREACH(m_pTextures, pElement) CCDICT_FOREACH(m_pTextures, pElement)
{ {
@ -552,6 +554,32 @@ void CCTextureCache::removeUnusedTextures()
m_pTextures->removeObjectForElememt(pElement); m_pTextures->removeObjectForElememt(pElement);
} }
} }
*/
/** Inter engineer zhuoshi sun finds that this way will get better performance
*/
if (m_pTextures->count())
{
// find elements to be removed
CCDictElement* pElement = NULL;
list<CCDictElement*> elementToRemove;
CCDICT_FOREACH(m_pTextures, pElement)
{
CCLOG("cocos2d: CCTextureCache: texture: %s", pElement->getStrKey());
CCTexture2D *value = (CCTexture2D*)pElement->getObject();
if (value->retainCount() == 1)
{
elementToRemove.push_back(pElement);
}
}
// remove elements
for (list<CCDictElement*>::iterator iter = elementToRemove.begin(); iter != elementToRemove.end(); ++iter)
{
CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", (*iter)->getStrKey());
m_pTextures->removeObjectForElememt(*iter);
}
}
} }
void CCTextureCache::removeTexture(CCTexture2D* texture) void CCTextureCache::removeTexture(CCTexture2D* texture)