Permalink
Browse files

Merge pull request #876 from minggo/gles20

optimize CCTextureCache::removeUnusedCache()
  • Loading branch information...
2 parents 88510a3 + 4829dc7 commit fea0c38b68deadfb581eb2b377e1c07e0fd1dfc2 @minggo committed Apr 28, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 cocos2dx/textures/CCTextureCache.cpp
@@ -28,6 +28,7 @@ THE SOFTWARE.
#include <string>
#include <cctype>
#include <queue>
+#include <list>
#include "CCTextureCache.h"
#include "CCTexture2D.h"
#include "ccMacros.h"
@@ -541,6 +542,7 @@ void CCTextureCache::removeAllTextures()
void CCTextureCache::removeUnusedTextures()
{
+ /*
CCDictElement* pElement = NULL;
CCDICT_FOREACH(m_pTextures, pElement)
{
@@ -552,6 +554,32 @@ void CCTextureCache::removeUnusedTextures()
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)

0 comments on commit fea0c38

Please sign in to comment.