/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import has from"./has.js";function t(t){return t?.release&&"function"==typeof t.release}function i(t){return t?.acquire&&"function"==typeof t.acquire}class e{constructor(t,i,e,s=1,o=0){this._creator=t,this._acquireFunction=i,this._releaseFunction=e,this.allocationSize=s,this._pool=new Array(o),this._initialSize=o;for(let r=0;r<o;r++)this._pool[r]=this._creator();this.allocationSize=Math.max(s,1)}destroy(){this.prune(0)}acquire(...t){let s;if(e.test.disabled)s=this._creator();else{if(0===this._pool.length){const t=this.allocationSize;for(let i=0;i<t;i++)this._pool[i]=this._creator()}s=this._pool.pop()}return this._acquireFunction?this._acquireFunction(s,...t):i(s)&&s.acquire(...t),s}release(i){i&&!e.test.disabled&&(this._releaseFunction?this._releaseFunction(i):t(i)&&i.release(),this._pool.push(i))}prune(t=this._initialSize){if(!(t>=this._pool.length)){for(let i=t;i<this._pool.length;++i){const t=this._pool[i];this._dispose(t)}this._pool.length=t}}_dispose(t){t.dispose&&"function"==typeof t.dispose&&t.dispose()}static{this.test={disabled:!!has("esri-tests-disable-memory-pools")}}}export{e as default};
