Created
June 27, 2012 17:09
Revisions
-
makc created this gist
Jun 27, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ package com.realaxy.operators{ import flash.utils.Dictionary; internal class Pool { private var instances : Dictionary =new Dictionary() ; private var instanceCounts : Dictionary =new Dictionary() ; public function getInstance ( type : Class ) : * { var cache : Vector.<*>; if ( instanceCounts[type] ) { cache = instances[type]; }else{ cache = new Vector.<*>(); instances[type] = cache; instanceCounts[type] = 0; } if ( instanceCounts[type] < cache.length ) { return cache[instanceCounts[type]++]; }else{ var object : * =new type(); cache[instanceCounts[type]++] = object; return object; } } public function resetCounts ( type : Class ) : void { if ( instanceCounts[type] ) { instanceCounts[type] = 0; } } public function resetAllCounts ( ) : void { for ( var type : Object in instanceCounts ) { instanceCounts[type] = 0; } } } }