Refactor #1198

Optimize CCTextureCache::removeUnusedTextures()

Added by Minggo Zhang about 1 year ago. Updated 12 months ago.

Status:Closed Start date:2012-04-28
Priority:Normal Due date:
Assignee:Minggo Zhang % Done:

100%

Category:all
Target version:cocos2d-2.0-rc0a-x-2.0

Description

Current implementation removes element when looping.
The efficiency is not so good.

The codes below, offered by inter engineer zhuoshi sun, will improve performance.

 //< modified by sunzhuoshi
     if (m_pTextures->begin())
      {
         CCTexture2D *texture = NULL;
         std::string key;
         std::list<std::string> keysToRemove;
          while (texture = m_pTextures->next(&key))
          {
             if (texture->retainCount() == 1)
              {
                 keysToRemove.push_back(key);
             }
         };
         m_pTextures->end();
         for (std::list<std::string>::iterator it=keysToRemove.begin(); it!=keysToRemove.end(); ++it)          {
             CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", (*it).c_str());             
             m_pTextures->removeObjectForKey(*it);
         }
     }     //>

The codes should be integrated into gles20 branch.

History

Updated by Minggo Zhang about 1 year ago

  • Subject changed from Optimize CCRenderTexture::removeUnusedTextures() to Optimize CCTextureCache::removeUnusedTextures()

Updated by Minggo Zhang about 1 year ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Applied in changeset commit:564a366218133946b625a26c953470da391e7c25.

Updated by Minggo Zhang about 1 year ago

Applied in changeset commit:a51143239d70998bd84646a8acd1e7475adfb3c5.

Updated by Zhe Wang 12 months ago

  • Project changed from cocos2d-x to native
  • Category deleted (5)
  • Target version deleted (23)

Updated by Minggo Zhang 12 months ago

Applied in changeset commit:564a366218133946b625a26c953470da391e7c25.

Updated by Minggo Zhang 12 months ago

Applied in changeset commit:a51143239d70998bd84646a8acd1e7475adfb3c5.

Updated by Zhe Wang 12 months ago

  • Target version set to cocos2d-2.0-rc0a-x-2.0

Updated by Minggo Zhang 12 months ago

  • Category set to 12
  • Status changed from Resolved to Closed

Also available in: Atom PDF