(buffer: Buffer, originalSize: number)
| 3268 | return Buffer.allocUnsafe(poolSize); |
| 3269 | } |
| 3270 | returnBuffer(buffer: Buffer, originalSize: number): void { |
| 3271 | const poolSize = Math.max(1024, Math.pow(2, Math.ceil(Math.log2(originalSize)))); |
| 3272 | // Only return if it's the right size for the pool |
| 3273 | if (buffer.length !== poolSize) { |
| 3274 | return; // Different size, don't pool it |
| 3275 | } |
| 3276 | let pool = this.pools.get(poolSize); |
| 3277 | if (!pool) { |
| 3278 | pool = []; |
| 3279 | this.pools.set(poolSize, pool); |
| 3280 | } |
| 3281 | // Return buffer to pool for reuse (but don't let pool grow too large) |
| 3282 | if (pool.length < this.MAX_POOL_SIZE) { |
| 3283 | pool.push(buffer); |
| 3284 | } |
| 3285 | // If pool is full, let buffer get garbage collected |
| 3286 | } |
| 3287 | // Clear all pools (useful for cleanup) |
| 3288 | clear(): void { |
| 3289 | this.pools.clear(); |
no test coverage detected